Linux系统MySQL数据导出csv/txt格式文件报错

2022-10-30  本文已影响0人  南湘嘉荣
一、问题描述

MySQL服务器导出数据到csv文件,导出语句如下:

select * from test into outfile '/usr/local/user.csv' fields terminated by ","  escaped by '' optionally enclosed  by ''   lines terminated by '\n' ;

但是,报错:

1290 - The MySQL server is running with the --secure-file-priv option so it cannot execute this statement, Time: 0.066000s
二、问题分析

上面语句之所以报错,是由于MySQL的属性secure_file_priv设置了默认值。这就意味着我们只能导出文件到这个默认的目录下。我们可以查看该属性配置的值:

show variables like '%secure%';

我们可以看到此时的默认值为:


结果.png

当secure_file_prive=null,限制mysqld 不允许导入导出;当secure_file_priv=/var/lib/mysql-files/,限制mysqld的导入导出只能发生在/var/lib/mysql-files/目录下;当secure_file_priv=' ',不对mysqld的导入导出做限制。

三、解决办法

可以直接修改mysql的配置文件my.cnf,将secure_file_priv的值设为''即可。也可以在导出的时候不指定导出目录,这样下载的文件就在默认的目录/var/lib/mysql-files下。

select * from test into outfile fields terminated by ","  escaped by '' optionally enclosed  by ''   lines terminated by '\n' ;
上一篇 下一篇

猜你喜欢

热点阅读