MySQL 5.7.22 ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option

本文介绍了如何解决MySQL运行时因--secure-file-priv选项导致无法执行导出CSV文件的问题。通过修改配置文件my.cnf中的secure_file_priv参数并重启MySQL服务,成功实现了从MySQL表中导出CSV文件。

运行环境:CentOS7.4+MySQL5.7.22

将表数据导出为csv文件的时候报错

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

mysql> select * from  benchmark.benchmark order by thread into outfile '/tmp/benchmark.csv';
ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement

mysql> select version();
+-----------+
| version() |
+-----------+
| 5.7.22    |
+-----------+
1 row in set (0.00 sec)
mysql> show variables like 'secur%';
+------------------+-------+
| Variable_name    | Value |
+------------------+-------+
| secure_auth      | ON    |
| secure_file_priv | NULL  |
+------------------+-------+
2 rows in set (0.01 sec)


mysql> set global secure_file_priv='/tmp';
ERROR 1238 (HY000): Variable 'secure_file_priv' is a read only variable
mysql> 
系统默认值为NULL,并不支持动态修改此参数。
需要写到配置文件my.cnf中重启mysql。

# cat /etc/my.cnf | grep -i priv
[mysqld]
secure_file_priv = /tmp
mysql> show variables like 'secur%';
+------------------+-------+
| Variable_name    | Value |
+------------------+-------+
| secure_auth      | ON    |
| secure_file_priv | /tmp/ |
+------------------+-------+
2 rows in set (0.00 sec)
---重试导出csv文件:
mysql> select * from  benchmark.benchmark order by 1 into outfile "/tmp/benchmark.csv";
Query OK, 11 rows affected (0.00 sec)
此时导出正常!

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值