博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
MySQL导出查询数据出现--secure-file-priv选项问题
阅读量:4091 次
发布时间:2019-05-25

本文共 1529 字,大约阅读时间需要 5 分钟。

一、问题描述

Windows平台的MySQL5.7.12版本使用以下命令导出查询结果到Excel文件时,会出现问题

select sid, sname, age from studentinto outfile 'D:/Files/student.xlsx';
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 ... into outfile ...语句、LOAD_FILE()函数等。

具体怎么影响如文档所说:

secure_file_priv may be set as follows:If empty, the variable has no effect. This is not a secure setting.If set to the name of a directory, the server limits import and export operations to work only with files in that directory. The directory must exist; the server will not create it.If set to NULL, the server disables import and export operations.

所以,估计是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值

1、首先找到MySQL在使用的配置文件my.ini

mysql> select @@basedir;+----------------------------------------+| @@basedir                              |+----------------------------------------+| D:\Software\MySQL\mysql-5.6.43-winx64\ |+----------------------------------------+1 row in set (0.00 sec)

my.ini就在安装目录下,不过有的人有可能安装MySQL时的配置问题,导致MySQL读的不是安装路径下的my.ini文件(如下面链接所示),这种情况只要修改那个配置文件即可。

2、打开my.ini

secure_file_priv=

也就是设置为对文件的导入导出不做任何限制

3、重启MySQL服务

在cmd下依次执行以下命令

net stop mysql
net start mysql

此时,再执行原先的导出文件命令就没有问题了

 

参考链接:

转载地址:http://zdnii.baihongyu.com/

你可能感兴趣的文章
No devices detected. Fatal server error: no screens found
查看>>
db db2_monitorTool IBM Rational Performace Tester
查看>>
postgresql监控工具pgstatspack的安装及使用
查看>>
swift中单例的创建及销毁
查看>>
IE不支持option的display:none属性
查看>>
[分享]mysql内置用于字符串型ip地址和整数型ip地址转换函数
查看>>
【JAVA数据结构】双向链表
查看>>
【JAVA数据结构】先进先出队列
查看>>
移植Vim配色方案到Eclipse
查看>>
谈谈加密和混淆吧[转]
查看>>
关于按钮的mouseOver和rollOver
查看>>
Socket经验记录
查看>>
对RTMP视频流进行BitmapData.draw()出错的解决办法
查看>>
SecurityError Error 2148 SWF 不能访问本地资源
查看>>
乘法逆元
查看>>
Objective-C 基础入门(一)
查看>>
JVM内存模型_Minor GC笔记
查看>>
SpringCloud学习之PassCloud——(一)PassCloud源代码下载
查看>>
Nginx篇-springCloud配置Gateway+Nginx进行反向代理和负载均衡
查看>>
缓存篇-Redis缓存失效以及解决方案
查看>>