导出
select * into OUTFILE 'D:\sc.csv'
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\n'
from cmf_stu where id>248305
FIELDS TERMINATED BY ‘,’ 字段间分割符
OPTIONALLY ENCLOSED BY ‘"’ 将字段包围 数值型无效
LINES TERMINATED BY ‘\n’ 行分割符 换行符
导入
LOAD DATA local INFILE '/www/wwwroot/test/sc.csv'
INTO TABLE cmf_stu
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\n'
注意问题
- 导出报错
The MySQL server is running with the --secure-file-priv option so it cannot execute this statement
在my.ini 文件修改 secure-file-priv="
- 导入报错
Access denied for user 'xxx'@'xxx' (using password: YES)
普通用户没有FILE Privilege权限,使用 local 参数,上文已使用
参考链接
- https://www.cnblogs.com/bbcar/p/3830891.html
- https://www.cnblogs.com/Braveliu/p/11411272.html