mysql 5.7导数据报错 --secure-file-priv 处理

开发要求把表中数据导出到csv,以下代码之前在mysql 5.6运行正常

select * from user into outfile '/tmp/user.csv' fields terminated by ',' optionally enclosed by '"' lines terminated by '\r\n';

-- fields terminated by   字段分隔符
-- optionally enclosed by 字段包围符(数值型字段无效)
-- lines terminated by    行间分隔符

但在5.7运行时遇到以下报错,无法执行

ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement

查看官方文档,secure_file_priv参数用于限制LOAD DATA, SELECT …OUTFILE, LOAD_FILE() 等命令,操作的文件应该导入导出到哪个指定目录。可选值如下:

  • 为 NULL(默认):mysql不允许导入或导出
  • 为 具体目录(例如/tmp):只能在指定目录执行导入导出,其他目录不能执行
  • 没有值:不限制,可在任意目录导入导出

 

查看我们的 secure_file_priv ,发现为NULL。如果是具体目录,只需将into outfile 后路径指定到该目录即可。

mysql> show global variables like '%secure_file_priv%';
+------------------+-------+
| Variable_name    | Value |
+------------------+-------+
| secure_file_priv | NULL  |
+------------------+-------+
1 row in set (0.00 sec)

注意secure_file_priv 参数是只读参数,不能使用set global命令修改。

mysql> set global secure_file_priv='';
ERROR 1238 (HY000): Variable 'secure_file_priv' is a read only variable


解决方法

修改参数文件,加入以下语句,约停机时间重启mysql。

secure_file_priv=''

查看secure_file_priv修改后的值

mysql> show global variables like '%secure_file_priv%';
+------------------+-------+
| Variable_name    | Value |
+------------------+-------+
| secure_file_priv |       |
+------------------+-------+
1 row in set (0.00 sec)

修改后再次执行,成功导出。

mysql> select * from user into outfile '/tmp/user.csv' fields terminated by ',' optionally enclosed by '"' lines terminated by '\r\n';
Query OK, 15 rows affected (0.00 sec)

 

参考

https://blog.csdn.net/fdipzone/article/details/78634992

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Hehuyi_In

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值