gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 01:52:35 25 4
gpt4 key购买 nike

我在 Ubuntu 中运行 MySQL。我在运行特定的一组查询时收到此错误。

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

当我在我的 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

最佳答案

尝试:

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)

关于php - Mysql 使 --secure-file-priv 选项为 NULL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37543177/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com