问题描述
报错:(3948, ‘Loading local data is disabled; this must be enabled on both the client and server sides’)
mysql的解决方法
Step1:
mysql> SET GLOBAL local_infile=1;
Query OK, 0 rows affected (0.00 sec)
查看
mysql> show global variables like 'local_infile';
Step2:
终端
mysql --local-infile=1 -u root
说明:也可以在 ~/.my.cnf的 [mysql]中添加local-infile=1
,这样就可以直接用mysql
进行登录了
Step3:
mysql> use school
Database changed
mysql>load data local infile '~/load-test.csv' into table student;
Result:
参考:Loading local data is disabled - this must be enabled on both the client and server sides
mycli的解决方法
Step1:
set global local_infile=true;
show global variables like 'local_infile';
Step2:
vim ~/.my.cnf
,在[client]中添加loose-local-infile=1
(mycli会加载.my.cnf中的 client 部分)
Step3:
输入 mycli
,启动 mycli
Step4:
使用下面命令,导入 csv 文件
load data local infile 'load-test.csv' into table student;
或者
load data local infile '/Users/macos/load-test.csv' into table student;
注意:不能使用~
,要用完整的路径名
参考:Importing csv file through mycli is impossible