文 | Promise Sun
一、Bug问题
系统环境:win11
运行环境:MySQL 8.0.28
图形工具:Navicat Premium 15
Bug描述: 在备份数据库时,运行SQL语句时报错:
eg:SQL语句:
select * from mysql_test.customers into outfile 'C:/BACKUP/backupfile.txt'
fields terminated by ',' optionally enclosed by '''' lines terminated by '?';
报错信息:

二、Bug分析
1.首先,翻译信息
报错信息:
The MySQL server is running with the --secure-file-priv option so it cannot execute this statement
翻译:MySQL服务器运行在secure-file-priv选项时,无法执行此语句。
2.然后,分析报错信息
1)mysql文件的导入和导出路径有默认的设置,secure-file-priv出现问题,说明SQL语句中传入的文件路径与默认的路径冲突,才会报错。
secure-file-priv的值有3种情况:
secure_file_prive=null —— 默认值为null,限制mysql,禁止导入导出文件
secure_file_prive=“” —— 表示不限制路径,允许mysql 导入导出文件
secure_file_prive=“D:/path” —— 指定路径,表示只允许在该路径目录下导入导出文件(这里的路径值可以自己设置)
2)查看secure-file-priv当前的值
可以使用下面两种命令行方式查看secure-file-priv当前的值(任选其一即可)
第一种查看方式:
show variables like '%secure%';
显示结果

第二种查看方式:
show variables like "secure_file_priv";
显示结果

3)从上面显示结果中,可以明确系统默认禁止mysql导入导出文件。重新设置一下secure-file-priv的值即可。
三、解决方案
1) 首先,找到你的mysql安装路径下的my.ini文件
注:若安装路径下没有找到此文件,可以在此安装路径下自己新建一个my.ini文件。
下图是本人的mysql安装路径,仅供参考

2) 打开my.ini文件,在文件末尾设置secure-file-priv的值。
secure-file-priv的值可以指定路径设置,也可以不限制路径。区别是指定路径相对安全,但在mysql导入导出文件时则必须在指定路径下才可以,否则依然会报错。
注:本人直接设置不限制路径,你可以自行决定是否设置指定路径
secure_file_prive=“”

3) 然后,my.ini文件 点击另存为窗口,编码选择ANSI,保存。**

4) 验证secure-file-priv当前的值是否设置成功。
注:成功设置后,就可以使用SQL语句了。
命令行查看:
show variables like "secure_file_priv";
验证结果:

版权声明:本文为博主原创文章,转载请点赞此文并注明出处,谢谢!
网友评论