MySQL导入导出CSV文件

MySQL自己提供了导入导出数据库的工具,但有时我们需要仅仅导入导出单个表的数据,比如导入导出CSV文件,此时可以使用MySQL自动的命令来做导入导出工作。

 


SELECT * FROM [TABLE] INTO OUTFILE '[FILE]';

 

或者

 


SELECT * FROM [TABLE] INTO OUTFILE '[FILE]' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n';

 

举个栗子

 




SELECT * FROM mytable INTO OUTFILE '/tmp/mytable.csv' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n';


 

导入语法如下:

 


LOAD DATA INFILE '[FILE]' INTO TABLE [TABLE];

 


LOAD DATA INFILE '[FILE]' INTO TABLE [TABLE] FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n';

 

举个栗子

 


LOAD DATA INFILE '/tmp/mytable.csv' INTO TABLE mytable FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n'; 

 

文章写得好 赏颗六味地黄丸补补

原创文章,转载请注明: 转载自 吴川斌的博客 https://www.mr-wu.cn

本文链接地址: MySQL导入导出CSV文件 https://www.mr-wu.cn/mysql-export-import-csv/

分享到微信
使用微信扫码将网页分享到微信

推荐文章

神评一下

你可以从微信分享这篇文章

只需要简单两步

1.点击右上角

2.选择分享到朋友圈