解决bug:the --secure-file-priv option so it cannot execute this statement

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
云数据库 RDS PostgreSQL,集群系列 2核4GB
简介: 解决bug:the --secure-file-priv option so it cannot execute this statement

一、Bug问题


系统环境:win11

运行环境:MySQL  8.0.28

图形工具:Navicat Premium 15

Bug描述: 在备份数据库时,运行SQL语句时报错:

eg:SQL语句:

select * from mysql_test.customers into outfile 'C:/BACKUP/backupfile.txt'
fields terminated by ','  optionally enclosed by '''' lines terminated by '?';


报错信息:


image.png

二、Bug分析


1.首先,翻译信息


报错信息:


The MySQL server is running with the --secure-file-priv option so it cannot execute this statement

翻译:MySQL服务器运行在secure-file-priv选项时,无法执行此语句。


2.然后,分析报错信息


1)mysql文件的导入和导出路径有默认的设置,secure-file-priv出现问题,说明SQL语句中传入的文件路径与默认的路径冲突,才会报错。

secure-file-priv的值有3种情况:

secure_file_prive=null            —— 默认值为null,限制mysql,禁止导入导出文件

secure_file_prive=“”               —— 表示不限制路径,允许mysql 导入导出文件

secure_file_prive=“D:/path”   —— 指定路径,表示只允许在该路径目录下导入导出文件(这里的路径值可以自己设置)

2)查看secure-file-priv当前的值

可以使用下面两种命令行方式查看secure-file-priv当前的值任选其一即可

第一种查看方式:

show variables like '%secure%';


显示结果

image.png

第二种查看方式:

show variables like "secure_file_priv";

显示结果

image.png

3)从上面显示结果中,可以明确系统默认禁止mysql导入导出文件。重新设置一下secure-file-priv的值即可。


三、解决方案


1) 首先,找到你的mysql安装路径下的my.ini文件

注:若安装路径下没有找到此文件,可以在此安装路径下自己新建一个my.ini文件。

下图是本人的mysql安装路径,仅供参考


image.png


2) 打开my.ini文件,在文件末尾设置secure-file-priv的值。

secure-file-priv的值可以指定路径设置,也可以不限制路径。区别是指定路径相对安全,但在mysql导入导出文件时则必须在指定路径下才可以,否则依然会报错。

注:本人直接设置不限制路径,你可以自行决定是否设置指定路径

secure_file_prive=“”


image.png


3) 然后,my.ini文件 点击另存为窗口,编码选择ANSI,保存。**

image.png


4) 验证secure-file-priv当前的值是否设置成功。

注:成功设置后,就可以使用SQL语句了。

命令行查看:

show variables like "secure_file_priv";

验证结果:

image.png

相关实践学习
如何在云端创建MySQL数据库
开始实验后,系统会自动创建一台自建MySQL的 源数据库 ECS 实例和一台 目标数据库 RDS。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
4月前
|
关系型数据库 MySQL 数据库
Mysql-错误处理: Found option without preceding group in config file
Mysql-错误处理: Found option without preceding group in config file
512 0
|
移动开发 JSON 关系型数据库
ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement
ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement
|
SQL 关系型数据库 MySQL
mysql Error Code: 1175. You are using safe update mode and you tried to update a table without ....
mysql Error Code: 1175. You are using safe update mode and you tried to update a table without ....
190 0
mysql Error Code: 1175. You are using safe update mode and you tried to update a table without ....