What's This Error?
So you're getting ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement. I know this one trips people up — it got me the first time too. You're trying to import a CSV or export query results to a file, and MySQL just slams the door.
This error shows up most often when you're doing something like this:
LOAD DATA INFILE 'C:/Users/You/data.csv' INTO TABLE mytable;
Or
SELECT * FROM mytable INTO OUTFILE 'C:/output/results.csv';
The fix is simple: MySQL only lets you read/write files from specific folders. That's secure_file_priv. Here's how to fix it in three easy levels.
Fix 1: 30 Seconds — Use the Right Folder
MySQL ships with a default secure folder. On Windows, it's often C:\ProgramData\MySQL\MySQL Server 8.0\Uploads\. On Linux, it's /var/lib/mysql-files/. Check yours by running:
SHOW VARIABLES LIKE 'secure_file_priv';
Copy your file into that folder. Then change your command to point there. For example:
LOAD DATA INFILE 'C:/ProgramData/MySQL/MySQL Server 8.0/Uploads/data.csv' INTO TABLE mytable;
If you're on Linux, it's something like:
LOAD DATA INFILE '/var/lib/mysql-files/data.csv' INTO TABLE mytable;
That's it. Your import should work now. This fix works 90% of the time and takes less than a minute.
Fix 2: 5 Minutes — Change the Config File
If you don't want to move files around (honestly, who does?), change the secure folder. You need to edit your MySQL config file. On Windows, it's usually C:\ProgramData\MySQL\MySQL Server 8.0\my.ini. On Linux, it's /etc/mysql/my.cnf or /etc/my.cnf.
- Open the file with admin rights (right-click Notepad and run as admin on Windows, or use
sudo nano /etc/mysql/my.cnfon Linux). - Find the
[mysqld]section. If it's not there, add it at the top. - Add or change this line:
secure_file_priv = "C:/MyFolder"On Linux, use a path like
/home/myuser/mysqlfiles. - Make sure the folder exists and MySQL can access it. On Linux, run
chown mysql:mysql /home/myuser/mysqlfilesandchmod 755 /home/myuser/mysqlfiles. - Restart MySQL:
- Windows: Services (run
services.msc), find MySQL80, right-click, restart. - Linux:
sudo systemctl restart mysqlorsudo service mysql restart.
- Windows: Services (run
Now your files will work from that folder. Quick tip: avoid spaces in the path — MySQL doesn't always handle them well.
Fix 3: 15+ Minutes — Disable Secure File Priv (Not Recommended)
I'm putting this here because people ask for it, but I don't like it. You can set secure_file_priv to an empty string to disable the restriction entirely. This is risky — it lets MySQL read and write files from anywhere on your server, which is a big security hole.
Only do this on a local dev box where you know what you're doing. Never on a production server.
- Open your MySQL config file (same as Fix 2).
- In the
[mysqld]section, set:secure_file_priv = "" - Restart MySQL.
- Now you can run any
LOAD DATA INFILEorSELECT...INTO OUTFILEfrom any path. But remember, you're living dangerously.
If you get an error after this, check the path permissions. On Linux, the mysql user needs read/write access to the folder. On Windows, the NETWORK SERVICE account usually needs access — right-click the folder, Properties, Security, Edit, add that account with full control.
Still Stuck?
If none of these work, check if your MySQL version changed the default. Some installers set a custom secure_file_priv path. Run SHOW VARIABLES LIKE 'secure_file_priv'; again and double-check the path exists. Also, if you're on a shared host, you can't change the config — use Fix 1 and move your file.
That's it. You're done. Go import your data.