我正在学习MySQL,并尝试使用LOAD DATA子句。当我使用它时,如下所示:

LOAD DATA INFILE "text.txt" INTO table mytable;

我得到了以下错误:

MySQL服务器正在使用——secure-file-priv选项运行,所以它不能执行这条语句

如何解决这个错误?

我已经检查了关于相同错误信息的另一个问题,但仍然找不到解决方案。

我使用的是MySQL 5.6


当前回答

我将LOCAL添加到命令中,但它产生了另一个问题:

Loading local data is disabled - this must be enabled on both the client and server sides

为了解决这个问题,我在这里简单地执行了三个步骤

其他回答

下面是我在Windows 7中禁用secure-file-priv的方法(vhu回答的选项#2):

进入services.msc停止MySQL服务器服务。 转到C:\ProgramData\MySQL\MySQL Server 5.6 (ProgramData在我的例子中是一个隐藏文件夹)。 在记事本中打开my.ini文件。 搜索“secure-file-priv”。 通过在行首添加'#'来注释该行。对于MySQL Server 5.7.16及以上版本,注释将不起作用。你必须将它设置为一个空字符串,就像这样- secure-file-priv="" 保存文件。 进入services.msc启动MySQL服务器服务。

对我有用的是:

Put your file inside of the folder specified in secure-file-priv. To find that type: mysql> show variables like "secure_file_priv"; Check if you have local_infile = 1. Do that typing: mysql> show variables like "local_infile"; If you get: +---------------+-------+ | Variable_name | Value | +---------------+-------+ | local_infile | OFF | +---------------+-------+ Then set it to one typing: mysql> set global local_infile = 1; Specify the full path for your file. In my case: mysql> load data infile "C:/ProgramData/MySQL/MySQL Server 8.0/Uploads/file.txt" into table test;

我将LOCAL添加到命令中,但它产生了另一个问题:

Loading local data is disabled - this must be enabled on both the client and server sides

为了解决这个问题,我在这里简单地执行了三个步骤

在Ubuntu 14和Mysql 5.5.53上,这个设置默认是启用的。要禁用它,你需要在mysqld配置组下的my.cnf文件中添加secure-file-priv = ""。如:-

[mysqld]
secure-file-priv = ""

在这篇文章发表时,这个帖子已经被浏览了570k次。说实话,MySQL什么时候变成了我们过度保护的无理妈妈了?这是多么耗费时间的安全尝试——这实际上只会束缚我们!

经过多次搜索和尝试,一切都失败了。 我的解决方案:

对我有用的是:

导入。csv文件通过PhpMyAdmin导入旧的盒子(如果大做在cmd行) 生成一个.sql文件。 下载。sql文件。 通过MySQL Workbench导入.sql文件。