mysql load data secure-file-priv问题

mysql数据库在出于安全性考虑时,在进行load data infile和into outfile操作时,经常会出现secure-file-priv问题:
在客户端执行:
mysql> load data infile "/tmp/file1.txt" into table t_serie_no fields terminated by ',' (transNo);
ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement
load data 操作:
在服务器端加local执行:
mysql> load data local infile "/tmp/file1.txt" into table t_serie_no fields terminated by ',' (transNo);
Query OK, 400000 rows affected (12.89 sec)
Records: 400000 Deleted: 0 Skipped: 0 Warnings: 0

into outfile操作:
mysql> select * from T_SCAN_RECORD_TOTAL into outfile '/tmp/T_SCAN_RECORD_TOTAL.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 variables like '%secure_file_priv%';
+------------------+-------+
| Variable_name | Value |
+------------------+-------+
| secure_file_priv | NULL |
+------------------+-------+
1 row in set (0.00 sec)

secure_file_priv值说明:
值为null ,表示限制mysqld 不允许导入|导出
值为/tmp/ ,表示限制mysqld 的导入|导出只能发生在/tmp/目录下
值没有具体值时,表示不对mysqld 的导入|导出做限制

此参数不可以在线修改:
mysql> set global secure_file_priv='';
ERROR 1238 (HY000): Variable 'secure_file_priv' is a read only variable

只能加入到my.cnf中重启服务器:
secure_file_priv=''

但是作为线上服务器,肯定不能随便重启,此时可以把文件拷贝到数据库服务器上,加上local执行:
load data local infile "/tmp/file1.txt" into table t_serie_no fields terminated by ',' (transNo);

猜你喜欢

转载自blog.51cto.com/1937519/2304609