Tuesday, 30 January 2018

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

When i executed the query i got the below error.

mysql> select * into outfile '/tmp/csr.txt' from CRS_STRATEGY_RULES;
ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement

The fix is to disable the secure_file_priv

mysql> show variables like secure_file_priv';
+------------------+-------+
| Variable_name    | Value |
+------------------+-------+
| secure_file_priv |       |
+------------------+-------+


The variable is an read-only variable  and we will need a mysql restart for the same.

Add the variable under [mysqld] in my.cnf as,

secure_file_priv=""

Do a mysql restart and you will be able to perform the query.

service mysqld restart

mysql> show variables like secure_file_priv%';
+------------------+-------+
| Variable_name    | Value |
+------------------+-------+
| secure_file_priv |       |
+------------------+-------+


mysql> select * into outfile '/tmp/csr.txt' from CRS_STRATEGY_RULES;
Query OK, 145 rows affected (0.00 sec)