Mysql使--secure-file-priv选项为NULL

时间:2016-05-31 10:28:40

标签: php mysql mysql-error-1064

我在Ubuntu中运行MySQL。我在运行特定查询集时遇到此错误。

  

MySQL服务器使用--secure-file-priv选项运行,因此无法执行此语句

当我在我的mysql服务器中SELECT @@secure_file_priv;时,我得到了/var/lib/mysql-files/。我想我需要将其发送到NULL

这是我正在运行的查询:

LOAD DATA INFILE :file INTO TABLE test_files
COLUMNS TERMINATED BY ',' ENCLOSED BY '\"'
LINES TERMINATED BY '\n';

现在的问题是如何制作这个NULL

1 个答案:

答案 0 :(得分:3)

尝试:

mysql> SELECT VERSION();
+-----------+
| VERSION() |
+-----------+
| 5.7.12-0  |
+-----------+
1 row in set (0.00 sec)

mysql> SELECT @@GLOBAL.secure_file_priv;
+---------------------------+
| @@GLOBAL.secure_file_priv |
+---------------------------+
| /var/lib/mysql-files/     |
+---------------------------+
1 row in set (0.00 sec)

更改档案:/etc/mysql/my.cnf

[mysqld]
.
.
.
secure_file_priv=NULL
.
.
.

重启MySQL。

mysql> SELECT @@GLOBAL.secure_file_priv;
+---------------------------+
| @@GLOBAL.secure_file_priv |
+---------------------------+
| NULL                      |
+---------------------------+
1 row in set (0.00 sec)

<强>更新

mysql> SELECT @@GLOBAL.secure_file_priv;
+---------------------------+
| @@GLOBAL.secure_file_priv |
+---------------------------+
| /var/lib/mysql-files/     |
+---------------------------+
1 row in set (0.00 sec)

档案:/var/lib/mysql-files/myfile.csv

1,"Row 1"
2,"Row 2"
3,"Row 3"
mysql> DROP TABLE IF EXISTS `test_files`;
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> CREATE TABLE IF NOT EXISTS `test_files` (
    ->   `col0` INT,
    ->   `col1` VARCHAR(20)
    -> );
Query OK, 0 rows affected (0.00 sec)

mysql> LOAD DATA INFILE '/var/lib/mysql-files/myfile.csv'
    -> INTO TABLE `test_files`
    -> COLUMNS TERMINATED BY ',' ENCLOSED BY '\"'
    -> LINES TERMINATED BY '\n';
Query OK, 3 rows affected (0.01 sec)
Records: 3  Deleted: 0  Skipped: 0  Warnings: 0

mysql> SELECT
->   `col0`,
->   `col1`
-> FROM
->   `test_files`;
+------+-------+
| col0 | col1  |
+------+-------+
|    1 | Row 1 |
|    2 | Row 2 |
|    3 | Row 3 |
+------+-------+
3 rows in set (0.00 sec)