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

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

作者: 南湘嘉荣 | 来源:发表于2022-10-30 09:50 被阅读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' ;
    

    相关文章

      网友评论

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

          本文链接:https://www.haomeiwen.com/subject/xgyctdtx.html