I encountered such a problem: Error Code: 1290. The MySQL server is running with the --secure-file-priv option so it cannot execute this statement when I tried to execute MySQL statement (Windows):
SELECT * FROM xxxx WHERE XXX INTO OUTFILE 'report.csv' FIELDS TERMINATED BY '#' ENCLOSED BY '"' LINES TERMINATED BY '\n'
When I execute it without:
INTO OUTFILE 'report.csv' FIELDS TERMINATED BY '#' ENCLOSED BY '"' LINES TERMINATED BY '\n'
Then it works. Also, the same statement with INTO OUTFILE xxx
actually worked before I reinstalled the MySQL server.
Anybody has ideas how to deal with this error?
Fixing the MySQL error 1290 by reconfiguring and restarting msc then press Ctrl+Shift+Enter to run it as an administrator. Locate the MySQL service and double-click to open its properties dialog. Check the Path to Executable for the –defaults-file option to determine where my. ini file is located.
Diable secure-file-priv variable To disable it, set the variable to a NULL value. This was successful.
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.
A quick answer, that doesn't require you to edit any configuration files (and works on other operating systems as well as Windows), is to just find the directory that you are allowed to save to using:
mysql> SHOW VARIABLES LIKE "secure_file_priv"; +------------------+-----------------------+ | Variable_name | Value | +------------------+-----------------------+ | secure_file_priv | /var/lib/mysql-files/ | +------------------+-----------------------+ 1 row in set (0.06 sec)
And then make sure you use that directory in your SELECT
statement's INTO OUTFILE
clause:
SELECT * FROM xxxx WHERE XXX INTO OUTFILE '/var/lib/mysql-files/report.csv' FIELDS TERMINATED BY '#' ENCLOSED BY '"' LINES TERMINATED BY '\n'
Original answer
I've had the same problem since upgrading from MySQL 5.6.25 to 5.6.26.
In my case (on Windows), looking at the MySQL56 Windows service shows me that the options/settings file that is being used when the service starts is C:\ProgramData\MySQL\MySQL Server 5.6\my.ini
On linux the two most common locations are /etc/my.cnf
or /etc/mysql/my.cnf
.
Opening this file I can see that the secure-file-priv
option has been added under the [mysqld]
group in this new version of MySQL Server with a default value:
secure-file-priv="C:/ProgramData/MySQL/MySQL Server 5.6/Uploads"
You could comment this (if you're in a non-production environment), or experiment with changing the setting (recently I had to set secure-file-priv = ""
in order to disable the default). Don't forget to restart the service after making changes.
Alternatively, you could try saving your output into the permitted folder (the location may vary depending on your installation):
SELECT * FROM xxxx WHERE XXX INTO OUTFILE 'C:/ProgramData/MySQL/MySQL Server 5.6/Uploads/report.csv' FIELDS TERMINATED BY '#' ENCLOSED BY '"' LINES TERMINATED BY '\n'
It's more common to have comma seperate values using FIELDS TERMINATED BY ','
. See below for an example (also showing a Linux path):
SELECT * FROM table INTO OUTFILE '/var/lib/mysql-files/report.csv' FIELDS TERMINATED BY ',' ENCLOSED BY '"' ESCAPED BY '' LINES TERMINATED BY '\n';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With