【错误】MySQL5.7导出数据时提示ERROR 1290 (HY000)-secure-file-priv错误

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_27283619/article/details/89059780

【错误】MySQL5.7导出数据时提示-secure-file-priv错误)

1. 运行环境

Win10 + MySQL5.7.25

2. 问题描述

在到处数据时,报错: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

3. 问题原因

查看官方文档,secure_file_priv参数用于限制LOAD DATA, SELECT …OUTFILE, LOAD_FILE()传到哪个指定目录。

  • secure_file_priv 为 NULL 时,表示限制mysqld不允许导入或导出。
  • secure_file_priv 为 /tmp 时,表示限制mysqld只能在/tmp目录中执行导入导出,其他目录不能执行。
  • secure_file_priv 没有值时,表示不限制mysqld在任意目录的导入导出。
    我们可以查看secure_file_priv 的值,默认为NULL,表示限制不能导入导出。
mysql> SHOW GLOBAL VARIABLES LIKE "%secure_file_priv%";
+------------------+-------+
| Variable_name | Value |
+------------------+-------+
| secure_file_priv | NULL |
+------------------+-------+
1 row in set, 1 warning (0.00 sec)

4. 解决办法

因为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配置文件

  1. 在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 服务已成功停止。
  1. 重启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)

在这里插入图片描述
5. 注意事项
注意指定路径的时候一定要写对:

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)

5. 参考文献

mysql5.7导出数据提示–secure-file-priv选项问题的解决方法

猜你喜欢

转载自blog.csdn.net/qq_27283619/article/details/89059780