首页 >数据库 >mysql教程 >MySQL导入导出CSV文件_MySQL

MySQL导入导出CSV文件_MySQL

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB原创
2016-06-01 13:44:12824浏览

bitsCN.com

 

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'; 

 

摘自 kongxx的专栏

bitsCN.com
声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn