mysql load大文件时报错:ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option

引言

在使用load data infile导入百万级数据时报错。

异常复现

1、连接客户端

mysql --local-infile -uroot -proot

2、选择数据库

use database;

3、设置全局参数local_infile为1,开启从本地加载文件导入数据的开关

set global local_infile = 1;

4、开始导入本地数据

mysql> load data infile '/tb_sku4.sql' into table tb_sku fields terminated by ',' lines terminated by '\n';

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

报错原因

1、什么是secure-file-priv

安全的文件权限(pri -> privileges),那么,这个secure-file-priv又是什么玩意儿呢?查看mysql referman,如下:

在这里插入图片描述

2、查看secure-file-priv环境变量

mysql> select @@secure_file_priv;
+--------------------+
| @@secure_file_priv |
+--------------------+
| NULL		         |
+--------------------+

或者

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

根据上述的NULL值,可以看到是不允许导出(入)到文件。

3、修改mysql配置文件,vim my.cnf

# Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA

#
# The MySQL  Server configuration file.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

[mysqld]
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
datadir         = /var/lib/mysql

secure-file-priv=NULL

# 开启MySQL慢日志查询开关
slow_query_log=1
# # 设置慢日志的时间为2秒,SQL语句执行时间超过2秒,就会视为慢查询,记录慢查询日志
long_query_time=2

# Custom config should go here
!includedir /etc/mysql/conf.d/

secure-file-priv=NULL改为secure-file-priv="/secure-files"

这样,便可以将/secure-files/文件夹下的文件进行导入导出操作

然后重新执行导入文件步骤即可

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
### 回答1: 这个错误消息表明,MySQL服务器正在使用--secure-file-priv选项运行,因此无法执行此语句。这意味着MySQL服务器不允许在安全文件目录之外的任何位置进行文件操作。请检查文件的路径是否在安全文件目录中,或者更改MySQL服务器的配置以取消--secure-file-priv选项。 ### 回答2: ERROR 1290 (HY000): MySQL服务器正在使用--secure-file-priv选项运行,因此无法执行此语句。 这个错误通常是由于MySQL服务器运行配置了--secure-file-priv选项而导致的。这个选项的作用是为了提高数据的安全性,限制MySQL服务器只能从特定的目录中导入或导出文件。 当我们尝试执行一条语句,需要从MySQL服务器导入或导出文件,如果文件不在MySQL服务器所配置的--secure-file-priv目录中,就会出现此错误。 要解决这个问题,我们可以采取以下几个步骤: 1. 确认MySQL服务器的配置文件中是否设置了--secure-file-priv选项。可以通过查看my.cnf文件(在Linux系统中一般位于/etc/mysql/目录下)来确认。 2. 找到--secure-file-priv选项指定的目录。可以通过在MySQL服务器的命令行终端中执行`SHOW VARIABLES LIKE 'secure_file_priv';`命令来查看。 3. 将需要导入或导出的文件移动到--secure-file-priv指定的目录中。 4. 确保文件的权限设置正确,MySQL服务器需要具有足够的权限来读取或写入这些文件。 5. 在使用LOAD DATA INFILE或SELECT INTO OUTFILE语句,指定正确的文件路径。例如,如果需要导入文件,可以使用以下语句:`LOAD DATA INFILE 'file.csv' INTO TABLE table_name;` 通过以上步骤,我们可以解决ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement错误,使得MySQL服务器能够顺利执行包含文件导入或导出的语句。 ### 回答3: ERROR 1290 (HY000)是MySQL数据库报错的一种常见情况,它表示MySQL服务器在运行使用了--secure-file-priv选项,因此无法执行当前的语句。 这个错误的出现是因为MySQL的--secure-file-priv选项限制了文件系统上可以被导入或导出的文件的位置。通过设置了这个选项,MySQL可以提高系统的安全性,防止用户在执行导入和导出操作意外地操作到敏感的系统文件。 要解决这个错误,我们需要找到MySQL的配置文件my.cnf或my.ini文件,并搜索其中的--secure-file-priv选项,然后查看该选项的值。 在配置文件中,--secure-file-priv=指定了允许导入或导出文件的路径。默认情况下,该值指向了一个特定的目录,一般是/tmp或/var/lib/mysql-files。 如果我们需要执行当前的语句,可以考虑两种方法。一种方法是将要导入或导出的文件移动到--secure-file-priv指定的目录下。另一种方法是修改--secure-file-priv的值为允许导入或导出文件的目录。 修改配置文件后,我们需要重启MySQL服务器,使修改生效。修改后,就可以成功执行当前的语句了。 总结起来,ERROR 1290 (HY000)表示MySQL服务器配置了--secure-file-priv选项,导致无法执行当前的语句。要解决这个错误,我们需要找到配置文件并修改--secure-file-priv的值,或者将文件移动到--secure-file-priv指定的目录下。最后,需要重启MySQL服务器使修改生效。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

L-960

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值