需求:向本地 mysql 中导入 ratings.csv 文件(27773444 条记录)
环境:Win 10 + MySQL 5.7.29
不要使用 MySQL Workbench 的导入功能!对于数量庞大的数据导入极慢!
解决方案:通过命令行导入(要求列与列之间以 英文逗号 分割,若字段中含有 , 则以 " 包裹)
load data infile 'D:/mysql-5.7.29-winx64/files/ratings_5.csv' into table ratings fields terminated by ',' optionally enclosed by '"' escaped by '"' lines terminated by '\r\n';
踩坑一:文件路径用 \ 分割会报错,用 / 可(用 \\ 应该也可)
踩坑二:load data 命令报错
ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement
在 my.ini 中加入(空字符串代表允许从一切目录导入)
[mysqld]
secure-file-priv=''
然后再