Win10 + MySQL5.7.25
在到处数据时,报错:ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement。
mysql> SELECT *
-> FROM courses
-> INTO OUTFILE "D:\\DatabaseSoftware\\output\\courses4.txt";
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()传到哪个指定目录。
mysql> SHOW GLOBAL VARIABLES LIKE "%secure_file_priv%";
+------------------+-------+
| Variable_name | Value |
+------------------+-------+
| secure_file_priv | NULL |
+------------------+-------+
1 row in set, 1 warning (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
正确办法:修改my.ini配置文件
secure_file_priv = ""
保存退出,这个时候要稍微留意一下编码问题,如果后面发现无法启动mysql,可以参考我这篇文章【错误】Win10中MySQL5.7 net start mysql服务正在启动或停止中,请稍候片刻后再试一次
2. 退出MySQL,关闭MySQL服务
mysql> quit
Bye
D:\DatabaseSoftware\MySQL5.7.25\bin>net stop mysql
MySQL 服务正在停止.
MySQL 服务已成功停止。
D:\DatabaseSoftware\MySQL5.7.25\bin>net start mysql
MySQL 服务正在启动 .
MySQL 服务已经启动成功。
D:\DatabaseSoftware\MySQL5.7.25\bin>mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.25 MySQL Community Server (GPL)
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show global variables like '%secure_file_priv%';
+------------------+-------+
| Variable_name | Value |
+------------------+-------+
| secure_file_priv | |
+------------------+-------+
1 row in set, 1 warning (0.00 sec)
发现已经成功修改secure_file_priv为空。
4. 导出成功
mysql> use my_db;
mysql> SELECT *
-> FROM courses
-> INTO OUTFILE "D:\\DatabaseSoftware\\output\\courses4.txt";
Query OK, 10 rows affected (0.01 sec)
mysql> SELECT *
-> FROM courses
-> INTO OUTFILE "D:\DatabaseSoftware\output\courses5.txt"
-> ;
Query OK, 10 rows affected (0.00 sec)
这样写显示导出成功了,但是在目录下并没有发现courses5.txt文件。
mysql> SELECT *
-> FROM courses
-> INTO OUTFILE "D:\\DatabaseSoftware\\output\\courses5.txt";
Query OK, 10 rows affected (0.00 sec)
形式二:
mysql> SELECT *
-> FROM courses
-> INTO OUTFILE "D:/DatabaseSoftware/output/courses6.txt";
Query OK, 10 rows affected (0.00 sec)
mysql5.7导出数据提示–secure-file-priv选项问题的解决方法