mysql——通过命令将sql查询的结果导出到具体文件

引言

最近在修改线上数据的时候,需要现将修改的数据继续备份,但是线上客户的服务器是不能直接连接,而是通过了一台堡垒机,这就说我们不能通过可视化客户端直接连接mysql的,所以所有的操作都是需要通过sql语句的,下面看一下导出的sql:

mysql> select count(1) from table  into outfile '/tmp/test.xls';

直接在我们查询的结果后面增加 into outfile '路径即可',但是在开始的时候我后面添加的路径不是 /tmp 而是/data 这样执行以后抛出下面的错误:

The MySQL server is running with the --secure-file-priv option so it cannot execute this statement

 这是因为mysql设置的权限,我们可以通过下面sql查看一下权限设置:

show variables like '%secure%';

导出的数据必须是这个值的指定路径才可以导出,默认有可能是NULL就代表禁止导出,所以需要设置一下;

我们需要在/etc/mysql/mysql.conf.d/mysqld.cnf 文件的末尾进行设置,在末尾添加一句secure_file_priv="/"即可将数据导出到任意目录;

secure_file_priv

  1、限制mysqld 不允许导入 | 导出

    secure_file_prive=null

  2、限制mysqld 的导入 | 导出 只能发生在/tmp/目录下

   secure_file_priv=/tmp/

  3、不对mysqld 的导入 | 导出做限制

          secure_file_priv 

       4、可以导出至任意目录

            secure_file_priv="/"

这样设置以后我们就可以,实现我们一些自定义的的导出了!

猜你喜欢

转载自blog.csdn.net/u013045437/article/details/81275960
今日推荐