如何将csv文件导入MySQL

shell命令

root@debian:~# mysqlimport -uroot -p123456 --fields-terminated-by=',' --fields-enclosed-by='"' --fields-escaped-by='"' database_name /var/lib/mysql-files/table_name.csv

参数说明:
–fields-terminated-by,字段间的分割符。
–fields-enclosed-by,单字段的前后分界限符。
–fields-escaped-by,转义字符。
database_name,库名。
table_name,即是文件名又是表名,必须一致。

常见问题

mysqlimport: Error: 1290, The MySQL server is running with the --secure-file-priv option so it cannot execute this statement, when using table: ...

MySQL启动参数–secure-file-priv,指定了一个目录,默认是/var/lib/mysql-files/,要导入的文件必须放在此目录下,否则在会出现如上错误。

原文地址:https://www.cnblogs.com/ilovecpp/p/12750073.html