select into outline导出文件报错ERROR 1290的解决
mysql使用select into outline导出文本文件时报错ERROR 1290,导致
导出文本文件不成功。。本文介绍遇到这种情况应该如何解决。
一、问题描述
在应用数据中使用select into outline导出文本文件到/mysql/backup/t.txt文件中报ERROR 1290错误,提示 --secure-file-priv参数。
mysql> select * from t into outfile '/mysql/backup/t.txt'; ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement |
二、问题分析
查询secure_file_priv对应值.
mysql> show global variables like '%secure_file_priv%'; +------------------+-------+ | Variable_name | Value | +------------------+-------+ | secure_file_priv | NULL | +------------------+-------+ 1 row in set (0.15 sec) |
说明:如上所示,secure_file_priv值为null,表示限制不能导入导出.官方文档显示,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为只读参数,使用set global命令修改会出现如下告警.
mysql> set global secure_file_priv=''; ERROR 1238 (HY000): Variable 'secure_file_priv' is a read only variable |
解决办法:将该参数配置写入参数文件/etc/my.cnf 中,secure_file_priv=''添加到/etc/my.cnf 中,重启数据库。
再查询该参数值,如下:
mysql> show variables like '%secure_file_priv%'; +------------------+-------+ | Variable_name | Value | +------------------+-------+ | secure_file_priv | | +------------------+-------+ 1 row in set (0.02 sec) |
重新导出文本文件,导出成功,如下:
mysql> > select * from t into outfile '/mysql/backup/t.txt'; Query OK, 110 rows affected (0.00 sec) |