Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mysql making --secure-file-priv option to NULL

Tags:

I am running MySQL in Ubuntu. I getting this error while running specific set of queries.

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

When I did SELECT @@secure_file_priv; in my mysql server I got /var/lib/mysql-files/. I think I need to make this to NULL.

This is the query I am running:

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

Now the question is how to make this NULL?

like image 864
Prabhu Khanna Mahadevan Avatar asked May 31 '16 10:05

Prabhu Khanna Mahadevan


People also ask

How do I fix priv secure file?

To overcome this error, you either need to remote the --secure-file-priv setting from your my. cnf file, or load your data from a directory specified in the value of the variable. Once you do so, your data should be loaded in without any issues!

How do I change the secure file priv in MySQL workbench?

The secure_file_priv value is a read-only value, so you can't change it directly using SQL query. To change the value of secure_file_priv variable, you need to create a MySQL configuration file that sets the value of the variable under [mysqld] options.

How do I disable secure file priv in MySQL workbench secure file priv?

To disable it, set the variable to a NULL value. This was successful. You have learned to configure secure-file-priv variable to fit your use case. Until next time, thanks for using our guide to solve “MySQL server is running with the –secure-file-priv” error when trying to load or save data.


1 Answers

Try:

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)

Change file: /etc/mysql/my.cnf

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

Restart MySQL.

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

UPDATE

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

File: /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)
like image 173
wchiquito Avatar answered Sep 28 '22 02:09

wchiquito