利用mysql client5.7导入导出CSV数据

导出

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'

注意问题

  1. 导出报错The MySQL server is running with the --secure-file-priv option so it cannot execute this statement

在my.ini 文件修改 secure-file-priv="

  1. 导入报错 Access denied for user 'xxx'@'xxx' (using password: YES)

普通用户没有FILE Privilege权限,使用 local 参数,上文已使用

参考链接

  1. https://www.cnblogs.com/bbcar/p/3830891.html
  2. https://www.cnblogs.com/Braveliu/p/11411272.html
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章