将csv 文件存入mysql 报错The MySQL server is running with the --secure-file-priv option so it cannot execute

系统:windows10
mysql版本:mysql 8.0

step1:用create语句创建database和table
step 2: 用下列语句将 csv 文件写入table
(#表注释)
load data infile ‘C:\Users\tsing\Desktop\wc.csv’ #1
into table project.wc character set gb2312 #2
fields terminated by ‘,’ optionally enclosed by ‘"’ escaped by ‘"’
lines terminated by ‘\r\n’;

#1:csv文件的路径
#2:set gb2312 转码,csv文件包含中文时使用

将桌面文件存储到mysql时报错:
The MySQL server is running with the --secure-file-pri option so it cannot execute this.
报错原因:
mysql文件的导入和导出路径有默认的设置,即 secure-file-priv,当传入的csv文件路径与默认的路径冲突时就会报错。

secure-file-priv的值有三种情况:

secure_file_prive=null ––限制mysqld 不允许导入导出

secure_file_priv=/path/ – --限制mysqld的导入导出只能发生在默认的/path/目录下

secure_file_priv=’’ – --不对mysqld 的导入 导出做限制

step3:查看你的secure-file-priv设置:

show variables like ‘%secure%’;
输出默认值path

step4:找到名为my的配置设置文件:
在这里插入图片描述
我这里的my文件在step3里查找的路径下:
C:\ProgramData\MySQL\MySQL Server 8.0\my

step4: 打开my文件,ctrl+f找到关键字secure,修改原路径:
把原路径用#注释掉,改为自定义路径,注意路径用的是斜杠,不是反斜杠
我将路径设置成空,意味着不对mysqld 的导入 导出做限制
在这里插入图片描述

step5. 设置完了保存,关闭。
step6. 重启mysql
重启方式:
打开计算机管理>>服务与应用程序>>服务>>mysql>>右键重新启动>>完成重启

step7:检验secure_file_priv是否设置成功
show variables like ‘%secure%’;

是空的,和刚才设置的一样,表明设置成功!
在这里插入图片描述
接下来就可以做常规的导入导出操作了:
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_44595372/article/details/88723191