• mysql可使用into outfile参数把表中的数据到处到csv,示例如下:

    select user_id from weibo_comment into outfile '/home/dazhan/comment.csv' lines terminated by '\n';

    执行后,weibo_comment表中的user_id字段就会被导出/home/dazhan/comment.csv

  • 参数说明:

    • into outfile导出的目录和文件名

      指定导出的目录和文件名

    • fields terminated by字段间分隔符

      定义字段间的分隔符

    • optionally enclosed by字段包围符

      定义包围字段的字符(数值型字段无效)

    • lines terminated by行间分隔符

      定义每行的分隔符

  • 问题分析:

    • 以上实例在实际的运行中出现如下错误:

      mysql> select user_id from weibo_comment into outfile '/home/dazhan/comment.txt' lines terminated by '\n';
      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-privNULL时,表示限制mysqld不允许导入或导出。

      • secure-file-priv/var/lib/mysql-files/时,表示限制mysqld只能在/var/lib/mysql-files/目录中执行导入导出,其他目录不行。

      • secure-file-priv没有值时,表示不限制mysqld在任意目录的导入导出。

    • 查看secure-file-priv的值(默认值是NULL)的命令如下:

      mysql> show global variables like '%secure_file_priv%';
      +------------------+-----------------------+
      | Variable_name | Value |
      +------------------+-----------------------+
      | secure_file_priv | /var/lib/mysql-files/ |
      +------------------+-----------------------+
      1 row in set (0.01 sec)

      这是我的查询结果,所以,我只需要把上述的输出目录改为/var/lib/mysql-files/就可以进行数据导出。

  • 修改secure-file-priv参数值的方法:

    • 打开my.cnf或my.ini,加入如下语句后重启mysql服务。

      secure_file_priv=''
    • 查看修改后的值:

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

      这样修改后,就可以在任意目录进行数据导入导出了。

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

  1. 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 ...

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

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

  3. SqlBulkCopy批量插入数据时,不执行触发器和约束的解决方法

    原文:SqlBulkCopy批量插入数据时,不执行触发器和约束的解决方法 在new SqlBulkCopy对象的时候,设置一下SqlBulkCopyOptions选项即可,按位或运算 SqlBulkC ...

  4. SpringMVC提交数据遭遇基础类型和日期类型报400错误解决方法

    使用SpringMVC开发的时候,页面如果有日期格式的数据,后台接受也是java.util.Date,则报告400错误 .下面是解决方案的演示示例: 这个是实体类,里面createDate就是java ...

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

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

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

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

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

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

  8. 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 ...

  9. [转]Navicat for oracle 提示 cannot load oci dll,193的解决方法 orcale 11g

    Navicat for oracle 提示 cannot load oci dll,193的解决方法   内网有一台windows server 2012,安装了Navicat 11.1.8 连接or ...

随机推荐

  1. SQL 表值函数/标量函数

    表值函数 定义表值函数 --定义表值函数 CREATE FUNCTION GetStuScore(@Stu_ID INT ) RETURNS TABLE AS RETURN (SELECT ),[St ...

  2. 毕业设计(3)基于MicroPython的篮球计时计分器模型的设计与实现

    前言 我们身边有不少人都喜欢看篮球比赛或者经常打篮球.说起篮球,肯定要提到NBA(美国职业篮球联赛),现在也正是NBA 18-19赛季常规赛的时候.最近3月5日,韦少22分帮助雷霆终结了四连败,哈登4 ...

  3. boost学习目录

    Boost之数值转换lexical_cast https://www.cnblogs.com/TianFang/archive/2013/02/05/2892506.html Boost之字符串算法s ...

  4. HTML HTML5 新特性

    一.语义化标签 语义化标签 为页面提供了更好的页面结构. 描述 属性 <header></header>  定义文档的头部区域 <footer></foote ...

  5. 如何用Eclipse创建一个JavaSwing的项目

    创建之前必须先给开发工具安装WindowBuilder插件(安装方法可自行百度) 方式一: 创建项目 new--other--WindowBuilder--SWT Designer----SWT/JF ...

  6. LR socket协议脚本

    socket协议分为TCP.UDP两种(区别与联系在此不做赘述),一种为长连接.一种为短连接.如果创建连接时在init中对应关闭连接在end中,则为长连接:如果创建关闭连接都是在action则为短连接 ...

  7. vue -- element

    1.页面 加载初始化 (function () { })();2.input 绑定键盘事件 @keyup.enter.native="onEnterSearch"@keyup.es ...

  8. Spring Bean's life

    In contrast, the lifecycle of a bean in a Spring container is more elaborate. It’simportant to under ...

  9. Linux查看用户所属用户组

    1.查看当前用户所属用户组 [oracle@serverhl ~]$ groups oinstall dba 2.查看<user1>, <user2> 和 <user3& ...

  10. .Net Core学习地址

    官方教程:https://docs.microsoft.com/zh-cn/aspnet/core/ 入门无忧网:http://www.rm5u.com/netcore/netcore-intro.h ...