例如在如下表中插入10W条数据:
第一种方法:在Mysql Workbench中用.csv文件导入10W条数据(相当于insert语句):
十分钟后:
第二种方法:(快速)
先查看local_infile状态:
show global variables like 'local_infile';
如果为OFF,则使用load data会报错。
修改方法:
set global local_infile=1;
然后执行如下语句:
load data local infile 'D:/ALL_LEARN/c/test/userinfo.txt'
into table userinfo
fields terminated by ' ' #空格作为分列符号
lines terminated by '\n' #回车作为分行符号
(user_id, username, gender, age, c_id);
运行:
仅用了1.04秒!
参考文章: