Home › Databases

ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement — how to fix

ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement

Quick fix: Run SHOW VARIABLES LIKE 'secure_file_priv'; and write/read files only inside that directory (e.g. /var/lib/mysql-files/). For importing client-side files use LOAD DATA LOCAL INFILE with local_infile enabled. To change it, set secure-file-priv= in my.cnf under [mysqld] and restart MySQL.

What it means

secure_file_priv restricts which server-side directory MySQL may read from (LOAD DATA INFILE, LOAD_FILE()) and write to (SELECT ... INTO OUTFILE). Check it:

SHOW VARIABLES LIKE 'secure_file_priv';
Value Meaning
a path, e.g. /var/lib/mysql-files/ only files in that directory
empty string any path the mysqld user can access
NULL import/export disabled entirely

Default on Linux packages is /var/lib/mysql-files/; on Windows C:\ProgramData\MySQL\MySQL Server 8.0\Uploads\.

Fix 1: use the allowed directory

SELECT id, name, email
INTO OUTFILE '/var/lib/mysql-files/users.csv'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\n'
FROM users;

Then copy it out: sudo cp /var/lib/mysql-files/users.csv ~/. On Windows use forward slashes: 'C:/ProgramData/MySQL/MySQL Server 8.0/Uploads/users.csv'.

INTO OUTFILE won't overwrite an existing file (error 1086); delete it first. The file is written on the database server, not your client machine.

Fix 2: import a client-side file with LOAD DATA LOCAL

LOCAL makes the client read the file and send it, so secure_file_priv doesn't apply:

mysql --local-infile=1 -u root -p mydb
SET GLOBAL local_infile = 1;   -- server side, needs admin
LOAD DATA LOCAL INFILE '/home/me/users.csv'
INTO TABLE users
FIELDS TERMINATED BY ',' ENCLOSED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 LINES;

Without both settings you get ERROR 3948 (42000): Loading local data is disabled. In MySQL Workbench add OPT_LOCAL_INFILE=1 under Connection → Advanced → Others.

Fix 3: export from the client instead

You often don't need INTO OUTFILE at all:

mysql -u root -p -B -e "SELECT * FROM users" mydb > users.tsv

-B gives tab-separated output. Convert CSV to JSON afterwards with the CSV to JSON tool if needed.

Fix 4: change secure_file_priv

It's read-only at runtime; set it in the config and restart. In /etc/mysql/mysql.conf.d/mysqld.cnf (or my.cnf / my.ini):

[mysqld]
secure-file-priv = /srv/mysql-io
sudo mkdir -p /srv/mysql-io && sudo chown mysql:mysql /srv/mysql-io
sudo systemctl restart mysql

secure-file-priv = "" removes the restriction, which is less secure. On Ubuntu, AppArmor also limits mysqld paths; add the new directory to /etc/apparmor.d/local/usr.sbin.mysqld and reload AppArmor. In Docker, pass --secure-file-priv=/path as a command argument and mount that directory.

The user also needs the FILE privilege for server-side files: GRANT FILE ON *.* TO 'app'@'localhost';.

Last updated 2026-11-22.