导出数据提示--secure-file-priv选项问题的解决方法

2023-05-16

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

1

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,表示限制不能导入导出。

1

2

3

4

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命令修改。

1

2

mysql> set global secure_file_priv='';

ERROR 1238 (HY000): Variable 'secure_file_priv' is a read only variable

解决方法

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

1

secure_file_priv=''

查看secure_file_priv修改后的值

1

2

3

4

mysql> show global variables like '%secure_file_priv%';

+------------------+-------+| Variable_name    | Value |

+------------------+-------+| secure_file_priv |       |

+------------------+-------+1 row in set (0.00 sec)

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


';  

执行后,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,表示限制不能导入导出。

1

2

3

4

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命令修改。

1

2

mysql> set global secure_file_priv='';

ERROR 1238 (HY000): Variable 'secure_file_priv' is a read only variable

解决方法

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

1

secure_file_priv=''

查看secure_file_priv修改后的值

1

2

3

4

mysql> show global variables like '%secure_file_priv%';

+------------------+-------+| Variable_name    | Value |

+------------------+-------+| secure_file_priv |       |

+------------------+-------+1 row in set (0.00 sec)

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

1

2

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)

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

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

随机推荐

  • OpenCV绘图相关操作 C++

    绘制相关知识 lineType线条风格介绍 opencv的线条风格由枚举值描述 xff1a span class token comment type of line span span class token keyword enum s
  • C++单例模式的几种实现

    单例模式 Singleton Pattern 的概念 模式定义 保证一个类仅有一个实例 xff0c 并提供一个访问它的全局访问点 饿汉单例和懒汉单例 常见的单例模式有两个分支 xff0c 饿汉单例和懒汉单例 饿汉单例是指在程序初始化时就把单
  • OpenCV深度图转点云

    需要先进行畸变校正 xff0c 再通过深度图转点云 相机的相关参数需要事先通过标定获得 span class token macro property span class token directive hash span span cl
  • 贝叶斯分类器,什么是朴素贝叶斯,后续为使用贝叶斯实现海量数据的邮件筛选。带源码数据集和解决思路

    朴素贝叶斯分类器 任务 xff1a 理解朴素贝叶斯分类器 实现我们的第一个贝叶斯分类器 使用朴素贝叶斯分类器分类邮件 概率论基础 xff1a 随机变量 xff1a 这个变量的值依赖于概率 抛硬币 xff08 其结果可能是正面 xff0c 也
  • [jetson]jetpack5.1的ubuntu20.04更换为清华源

    为使后续下载安装顺利 xff0c 需要给 Ubuntu 系统进行换源 Ctrl 43 Alt 43 T 打开终端 xff0c 输入如下命令 sudo gedit etc apt sources list 删除原文件内容 xff0c 添加如下
  • Windows系统借助WSL2可使用Linux系统开发

    一 起源 Windows 10 2004 发布后 xff0c WSL2 也可以在正式版 Windows 10 中使用 xff0c 相比于 macOS xff0c WSL2 是一个原生 Linux 环境而非类 unix 环境 xff0c 甚至
  • wiremock基本使用

    进入wiremock官网 xff0c 选择stand alone xff0c 下载jar包 http wiremock org docs running standalone 运行该jar包 xff0c 并设置端口号 xff0c 如 xff
  • 建行笔试题,最少补给品问题

    import java util Scanner public class Main public static void main String args Scanner sc 61 new Scanner System in Strin
  • springboot传递参数并选择激活环境运行jar包

    java jar spring boot demo 0 0 1 SNAPSHOT jar SOME ENV 61 always spring profiles active 61 prod
  • springcloud alibaba

    springcloud alibaba 版本说明 https github com alibaba spring cloud alibaba wiki E7 89 88 E6 9C AC E8 AF B4 E6 98 8E E6 AF 95
  • @JSONField的一些使用基础

    https blog csdn net dmw412724 article details 93761161
  • MyBatis Mapper 传递多个参数

    在pojo类对应的映射文件中 xff0c 对应的参数类型可以省略 传递方式 1 接口正常书写 xff0c 映射文件中SQL语句的占位符必须用 arg0 agr1 或param1 param2 接口 xff1a public Customer
  • MyBatis一对多的左连接查询、分步查询以及插入和删除操作

    例如有两张表 xff0c 分别是客户表和订单表 xff0c 一个客户有多个订单 xff0c 一个订单属于一个客户 两个实体类Customer Order 如下 xff1a package com itlike domain import l
  • 二叉树的构建及递归遍历

    定义结构体 public class Node int value Node left Node right public Node int value Node left Node right this value 61 value th
  • MySQL 多对多条件查询

    两个表 user和role 中间表是user role 查询用户和角色的对应关系 select res user name r role name from select u user name ur role id from user a
  • spring Bean相关配置及对象的生命周期

    名称与表示 xff1a id 使用了约束中的唯一约束 xff0c 里面不能出现特殊字符 name 没有使用唯一约束 xff0c 可以出现特殊字符 xff08 一般不使用 xff09 设置对象生命周期的方法 xff1a init method
  • 新博客开通

    xff01 xff5e 今天终于决定开博客了 并决定把全部觉得重要的东西都记录下来 每次都记录下来 然后一段时间再来总结一次 xff5e 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61
  • mybatis 代码生成器及多表联查的细节

    在使用mybatis代码生成器时 xff0c 若生成的字段要为布尔类型 xff0c 则在设计表时 xff0c 将字段属性设置为tinyint 长度设为1 这样 生成的domain中的 相应字段类型为布尔类型 如数据库中的字段类型为date或
  • yml自定义属性和值

    测试类 xff1a import com spx App import com spx config MyProperties import org junit Test import org junit runner RunWith im
  • 导出数据提示--secure-file-priv选项问题的解决方法

    mysql可使用 into outfile 参数把表中数据导出到csv xff0c 例如可用以下命令把user表的数据导出到user csv 1 select from user into outfile 39 tmp user csv 3