MySQL之select into outfile用法
短信预约 -IT技能 免费直播动态提醒
1、select into outfile可以导出数据到指定目录下的文件中
语法:
SELECT ... INTO OUTFILE 'file_name'
[CHARACTER SET charset_name]
[export_options]
export_options:
[{FIELDS | COLUMNS}
[TERMINATED BY 'string']
[[OPTIONALLY] ENCLOSED BY 'char']
[ESCAPED BY 'char']
]
[LINES
[STARTING BY 'string']
[TERMINATED BY 'string']
2、示例如下:
1)查看要导出数据的表t1
mysql> select * from t1;
+------+--------+
| id | name |
+------+--------+
| 1 | wang |
| 2 | steven |
| 3 | tiger |
| 4 | lilu |
+------+--------+
4 rows in set (0.00 sec)
2)查看导出的文件
[mysql@oneproxy outfile]$ more t1.file
1,"wang"
2,"steven"
3,"tiger"
4,"lilu"
3)创建要导入的表t2;
mysql> create table t2 as select * from t1 where 1=2;
Query OK, 0 rows affected (0.03 sec)
4)将导出的数据导入t2
mysql> LOAD DATA INFILE '/mysql/outfile/t1.file' INTO TABLE t2 FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n';
Query OK, 4 rows affected (0.01 sec)
Records: 4 Deleted: 0 Skipped: 0 Warnings: 0
5)查看导入的数据
mysql> select * from t2;
+------+--------+
| id | name |
+------+--------+
| 1 | wang |
| 2 | steven |
| 3 | tiger |
| 4 | lilu |
+------+--------+
4 rows in set (0.00 sec)
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341