mysql可使用 into outfile 参数把表中数据导出到csv,例如可用以下命令把user表的数据导出到user.csv

select * from user into outfile '/tmp/user.csv' fields terminated by ',' optionally enclosed by '"' lines terminated by '\r\n';

执行后,user表的数据会导出到/tmp/user.csv。

参数说明:
into outfile ‘导出的目录和文件名’
指定导出的目录和文件名

fields terminated by ‘字段间分隔符’
定义字段间的分隔符

optionally enclosed by ‘字段包围符’
定义包围字段的字符(数值型字段无效)

lines terminated by ‘行间分隔符’
定义每行的分隔符

问题分析
以上命令在mysql5.6下运行没有问题,但在mysql5.7下运行则出现了以下错误。

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

查看官方文档,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 (0.00 sec)

因为 secure_file_priv 参数是只读参数,不能使用set global命令修改。

mysql> set global secure_file_priv='';
ERROR 1238 (HY000): Variable 'secure_file_priv' is a read only variable

解决方法
打开my.cnf 或 my.ini,加入以下语句后重启mysql。

secure_file_priv=''

查看secure_file_priv修改后的值

mysql> show global variables like '%secure_file_priv%';
+------------------+-------+
| Variable_name | Value |
+------------------+-------+
| secure_file_priv |         |
+------------------+-------+
1 row in set (0.00 sec)

修改后再次执行,成功导出。

mysql> select * from user into outfile '/tmp/user.csv' fields terminated by ',' optionally enclosed by '"' lines terminated by '\r\n';
Query OK, 15 rows affected (0.00 sec)

原文链接:https://blog.csdn.net/fdipzone/article/details/78634992

mysql5.7导出数据提示--secure-file-priv选项问题的解决方法的更多相关文章

  1. Mongo导出数据文件导致错误 Got signal: 6 (Aborted)解决方法

    一哥们要导出一个数据表的数据,结果导出一半,硬盘不够用,卡死了, 然后重启主机,导致mongo启动后进程自动死掉, 报错如下. Mon Oct 28 10:39:02.270 [initandlist ...

  2. Oracle数据导入导出imp/exp sp2-0734:未知的命令开头'imp...解决方法

    Oracle数据导入导出imp/exp sp2-0734:未知的命令开头'imp...解决方法   sp2-0734:未知的命令开头'imp 忽略了剩余行默认分类   www.2cto.com  应该 ...

  3. Npoi Web 项目中(XSSFWorkbook) 导出出现无法访问已关闭的流的解决方法

    原本在CS项目中用的好好的在BS项目中既然提示我导出出现无法访问已关闭的流的解决方法 比较郁闷经过研究 终于解决了先将方法发出来 让遇到此问题的筒子们以作参考 //新建类 重写Npoi流方法 publ ...

  4. Parse error: syntax error, unexpected end of file in *.php on line * 解决方法

    Parse error: syntax error, unexpected end of file in *.php on line * 解决方法   这篇文章主要介绍了PHP错误Parse erro ...

  5. IntelliJ IDEA提示URI is not registered几种解决方法

    IntelliJ IDEA提示URI is not registered几种解决方法使用IntelliJ IDEA (以下简称IDEA)导入项目或是在maven生成  archetype时候,如果提示 ...

  6. safari无法调试iphone提示“无可检查的应用程序”的解决方法

    iphone上打开safari,随便访问一个网站,mac上通过Safari的开发,我的iphone是可以看到的.如果打开APP,就提示“无可检查的应用程序”. 解决方法 使用XCode运行我们的App ...

  7. 安装office2010提示要安装MSXML6.10.1129.0解决方法

    系统win7 32位 安装office2010出现了错误,提示要安装MSXML6.10.1129.0解决方法 1.下载MSXML6.10.1129.0进行安装 2.若本机已安装过不管用: a.在运行里 ...

  8. 安装JDK时提示 IllegalArgumentException:Invalid characters in hostname的解决方法

    今天在windows7_x64上安装JDK的时候提示IllegalArgumentException:Invalid characters in hostname, 解决方法: 1.打开[控制面板\系 ...

  9. InnoDB: Operating system error number 87 in a file operation. 错误87的解决方法

    InnoDB: Operating system error number 87 in a file operation. 错误87的解决方法 140628  8:10:48 [Note] Plugi ...

随机推荐

  1. nginx 配置 强制访问https

    使用nginx的301状态码 server { listen ;     if ($scheme = 'http') {    return 301 https://$server_name$requ ...

  2. [AH2017/HNOI2017] 影魔 - 线段树

    #include<bits/stdc++.h> #define maxn 200010 using namespace std; int a[maxn],st[maxn][2],top,L ...

  3. 深信服SCSA

    最近应公司要求报了SCSA课程,老师讲解的可谓是非常的专业以及详细,不止深信服产品及其配置,还有VPN,网络基础的原理介绍等等,产品不用说,工作中会遇到,能学即学.最好的要数网络发包原理,建立连接等底 ...

  4. Linux下用Bash语言实现输出最大值的功能

    题目链接: 题目描述 编写一个程序,输入a.b.c三个值,输出其中最大值. 输入 一行数组,分别为a b c 输出 a b c其中最大的数 样例输入 10 20 30 样例输出 30 复习下Linux ...

  5. 2020 Plan

    1. English IELTS  7.0 IELTS word 3271,  10 words diff 2 Grammar framework IELTS writing Friends foll ...

  6. js集合

    var list = {};//声明 List[0] = 52;//赋值 List[1] = 57;//赋值

  7. Spring整合MyBatis案例练习笔记

    需求: 用户登录 技术需求: Servlet+Spring+Mybatis+MVC+jsp+css+html+jquery 数据库设计: 用户表 Sql语句设计: select * from t_us ...

  8. HandlerMethod解析

    api写HandlerMethod的作用: Encapsulates information about a handler method consisting of a method and a b ...

  9. OpenCV3+VS2015 经常出现debug error abort()has been called问题

    方案1:图片路径错误:查看imread的路径

  10. 简单易用,用Powershell劫持Windows系统快捷键

    POC:  $WshShell = New-Object -comObject WScript.Shell $Shortcut = $WshShell.CreateShortcut("des ...