MySQL导入导出CSV

时间:2022-02-23 10:04:17

从CSV文件导入到MySQL:

LOAD DATA INFILE 'E:/file.csv'
INTO TABLE t1
CHARACTER SET gb2312
FIELDS TERMINATED BY ',' ENCLOSED BY '"'
LINES TERMINATED BY '\r\n'
(column1, @var1)
SET column2 = @var1/100;

 

从MySQL导出到CSV文件:

SELECT col1,col2,col3 FROM t1
INTO OUTFILE 'E:/file.csv'  
CHARACTER SET gb2312
FIELDS TERMINATED BY ',' ENCLOSED BY '"'
LINES TERMINATED BY '\r\n';

 

csv文件第一行不得有标题行,否则要在LINES TERMINATED BY "\r\n"后面添加
IGNORE 1 LINES