Got error: 1290: The MySQL server is running with the --secure-file-priv option so it cannot execute this statement when executing 'SELECT INTO OUTFILE

今天在使用​​mysqldump​​命令导出数据时,出现Got error: 1290: The MySQL server is running with the --secure-file-priv option so it cannot execute this statement when executing 'SELECT INTO OUTFILE’错误。

如图:

mysqldump导出数据 The MySQL server is running with the --secure-file-priv option so it cannot execute_mysql


出现此错误原因是因为在使用​​mysqldump​​​命令导出数据时如果加了​​-T​​​参数,代表导出两份文件,一份是​​.sql​​​,另一份是​​.txt​​文件。-T参数导出的数据文件必须是要在指定目录下才可以。

  • 查看当前mysql的默认导出路径:
mysql> select @@secure_file_priv;
+-----------------------+
| @@secure_file_priv |
+-----------------------+
| /var/lib/mysql-files/ |
+-----------------------+
1 row in set (0.00 sec)

mysql>

当前数据库导出的文件必须要在​​/var/lib/mysql-files/​​文件下才可以,否则就会出现刚刚的错误。

  • 重新导出:
mysqldump -uroot -padmin -T /var/lib/mysql-files/ test userinfo

mysqldump导出数据 The MySQL server is running with the --secure-file-priv option so it cannot execute_MySQL_02


进入​​/var/lib/mysql-files/​​查看导出的文件:

mysqldump导出数据 The MySQL server is running with the --secure-file-priv option so it cannot execute_mysql_03

问题解决!