在导入或导出时报错:> 1290 - The MySQL server is running with the --secure-file-priv option so it cannot execute this statement。在mysql的配置文件my.ini中添加以下代码:
[mysqld]
secure-file-priv=D:\
导出csv
# 将数据导出csv
SELECT * FROM db_table
INTO OUTFILE 'D:\temp.csv'
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\r\n'
;
# 在导出的csv首行增加自定义标题
SELECT '区划代码', '区划名称' UNION
SELECT field1, field2
FROM db_table
INTO OUTFILE 'D:\temp.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n';
导入csv
# IGNORE 0 ROWS 从第n行开始
LOAD DATA INFILE 'D:/tm_health_herb.csv'
INTO TABLE db_table
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
IGNORE 0 ROWS
(field1, filed2, field3...)