mysql 中的 secure-file-priv 报错处理
问题描述
当我要在 mysql 里导出数据的时候发现报错,报错内容如下
The MySQL server is running with the --secure-file-priv option so it cannot execute this statement
原理解释
secure-file-priv
是 mysql 中的一个系统变量,用来控制导入导出数据的操作,比如LOAD DATA
或SELECT ... INTO OUTFILE
或LOAD_FILE()
- 用
show global variables like 'secure_file%'
查看该变量的设定值,可能有以下 3 种取值- 1⃣️ 没有值。也就是这个变量没有作用了
- 2⃣️ 指向某个路径。也就是导入导出只能用这个路径
- 3⃣️
NULL
。禁止导入导出操作
- 不同平台的这个系统变量的默认值不一样
解决办法
-
环境:mysql 8.0.26(用
homebrew
安装),Macbook Pro 2020 Intel Edition -
1⃣️ 创建对应文件,
~/.my.cnf
,用自己习惯的文本编辑器即可,我用的nano
,里面内容如下[mysqld] secure_file_priv = ''
-
2⃣️ 重启 mysql 服务并登陆
brew services stop mysql brew services start mysql mysql -uroot -p # 输入密码后进入 msyql
-
3⃣️ 在 mysql 中查看是否修改成功,
show global variables like 'secure_file%'; # 如果修改成功应该显示如下内容,显示为空值 +------------------+-------+ | Variable_name | Value | +------------------+-------+ | secure_file_priv | | +------------------+-------+ 1 row in set (0.00 sec)
-
😄 这个时候就可以开心地导出数据了
参考
https://stackoverflow.com/questions/7973927/for-homebrew-mysql-installs-wheres-my-cnf
https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_secure_file_priv
本文来自博客园,作者:MartinLwx,转载请注明原文链接:https://www.cnblogs.com/MartinLwx/p/15376957.html
🚀🚀🚀博客园已不再更新文章,最新文章请查看👉Github pages