当执行以下sql语句来导出数据时:
mysql> select UserName, UserEmail from USERS
-> into outfile 'userData.txt'
-> files terminated by ','enclosed by '"'
-> lines terminated by '\n';
出现以下错误:
ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement
查询相关资料后,得知需要将导出路径设为secure_file_priv设定的路径,可以使用以下命令查询secure_file_priv的值:
mysql> show variables like '%secure%';
+------------------+-----------------------+
| Variable_name | Value |
+------------------+-----------------------+
| secure_auth | OFF |
| secure_file_priv | /var/lib/mysql-files/ |
+------------------+-----------------------+
2 rows in set (0.08 sec)
因此可以把前面的导出语句改为:
mysql> select UserName, UserEmail from USERS
-> into outfile '/var/lib/mysql-files/testData.txt'
-> fields terminated by ',' enclosed by '"'
-> lines terminated by '\n';
Query OK, 3 rows affected (0.20 sec)
或者在/etc/mysql/my.cnf配置文件中修改/添加以下字段:
secure_file_priv = yourPath
设置secure_file_priv为你想设置的路径,然后重启数据库。
参考博客:
MYSQL导出数据出现The MySQL server is running with the –secure-file-priv option
ERROR 1290 (HY000): The MySQL server is running with the –secure-file-priv option so it …statemet