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

Posted 青空如璃

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot exec相关的知识,希望对你有一定的参考价值。

 

今天在学习mysql时候,想要将文本文件的数据导入到数据库中,却发现一直报错,换了导入文本的路径也还是同样的错误,错误显示ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement。

 

然后在网上找解决办法,找的方法在Linux 下也不怎么好用,最后找到了解决Linux下MySQL文件导入出错的方法

出错的原因是因为在MySQL 5.7.6版本之后,导入文件只能在secure_file_priv指定的文件夹下(也有原因是因为权限不够)

 

 

方法一:

 

我们可以用show variables like ‘%secure%‘;命令显示文件目录

 

技术分享图片
 

这样将导入文件放在 /var/lib/mysql-files/文件夹下,之后再从这里导入就可以了

导出文件时候,也是将 文件导出到这个文件夹里。

 

load data infile ‘/var/lib/mysql-files/part.csv‘ into table PART fields terminated by ‘,‘  optionally enclosed by ‘"‘ escaped by ‘"‘ lines terminated by ‘ ‘;

 

如果显示ERROR 1261 (01000): Row 1 doesn‘t contain data for all columns
这个错误,是因为数据行不匹配,默认不能有空,用下列命令解决set sql_modul = 0;

 

 

下面两个方法主要针对windows下MySQL,Linux下MySQL的my.ini文件不好找

方法二:
 

修改MySQL安装路径下的my.ini,在末尾添加“secure-file-priv=路径名”这一行,重启mysql

将要通过load data infile的文件放在上面所定义的路径下进行操作即可

 

方法三:
 
    1. 停了mysql的服务。

    2. 在类似的这个位置C:ProgramDataMySQLMySQL Server 5.6my.ini, 找到INI文件。复制一份作为备份。

    3. 编辑此文件。将里面的类似的一行 secure-file-priv="C:/ProgramData/MySQL/MySQL Server 5.6/Uploads" 删除。

    4. 启动mysql服务。

在做mysql 大批量导出数据的时候,所遇到的问题如下:

 

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

 

mysql 默认对导出的目录有权限限制,也就是说使用命令行进行导出的时候,需要指定目录进行操作;

 

解决方法:

   1. 查询mysql 的secure_file_priv 值配置的是什么,使用命令行: show global variables like ‘%secure%‘;  

     (我这里的配置是 secure_file_priv = /var/lib/mysql-files/)

 

   2. 使用 into outfile 开始导出:(因为secure_file_priv配置的关系,所以必须导出到  /var/lib/mysql-files/目录下)

      select * from table_name where a = ‘test‘
into outfile ‘/var/lib/mysql-files/test.txt‘  FIELDS TERMINATED BY ‘,‘ OPTIONALLY ENCLOSED BY ‘"‘ LINES TERMINATED BY ‘ ‘;

 

  3.所用的几个关键字:

FIELDS TERMINATED BY  ‘,‘  OPTIONALLY ENCLOSED BY  ‘ " ‘  LINES TERMINATED BY ‘ ‘;

(因为导出的数据会出现一些乱码或者特殊字符,所以使用以上关键字进行转义)



以上是关于ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot exec的主要内容,如果未能解决你的问题,请参考以下文章

mysql 导出数据到文件数据异常 ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv op

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

mysql-修改密码(error-1290 (HY000): The MySQL server is running with the --skip-grant-tables option so)

mysql-修改密码(error-1290 (HY000): The MySQL server is running with the --skip-grant-tables option so)

ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot exe

MYSQL导入数据出现ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it