mysqldude

LOAD DATA INFILE

Version compatibility

StepMySQLMariaDB
5.65.78.08.4910.610.1111.411.8
LOAD DATA INFILE as a user without FILE privilege (post shows 1045)
original post
✓ 1045✓ 1045✓ 1045✓ 1045✓ 1045✓ 1045✓ 1045✓ 1045✓ 1045
LOAD DATA INFILE '/tmp/product.csv' as root (original path)
original post
✗ 1290✗ 1290✗ 1290✗ 1290✗ 1290✓✓✓✓
LOAD DATA INFILE from the secure_file_priv directory (modern)
modern rewrite
✓✓✓✓✓✓✓✓✓
GRANT FILE ON *.* (original fix)
original post
✓✓✓✓✓✓✓✓✓
UPDATE mysql.user SET File_priv = 'Y' + FLUSH PRIVILEGES (original alternative)
original post
✓✓✓✓⚠ 1681✗ 1356✗ 1356✗ 1356✗ 1356
LOAD DATA INFILE as a user without FILE privilege (post shows 1045) original post
MySQL 5.6✓ 10455.7✓ 10458.0✓ 10458.4✓ 10459✓ 1045
MariaDB 10.6✓ 104510.11✓ 104511.4✓ 104511.8✓ 1045
LOAD DATA INFILE '/tmp/product.csv' as root (original path) original post
MySQL 5.6✗ 12905.7✗ 12908.0✗ 12908.4✗ 12909✗ 1290
MariaDB 10.6✓10.11✓11.4✓11.8✓
LOAD DATA INFILE from the secure_file_priv directory (modern) modern rewrite
MySQL 5.6✓5.7✓8.0✓8.4✓9✓
MariaDB 10.6✓10.11✓11.4✓11.8✓
GRANT FILE ON *.* (original fix) original post
MySQL 5.6✓5.7✓8.0✓8.4✓9✓
MariaDB 10.6✓10.11✓11.4✓11.8✓
UPDATE mysql.user SET File_priv = 'Y' + FLUSH PRIVILEGES (original alternative) original post
MySQL 5.6✓5.7✓8.0✓8.4✓9⚠ 1681
MariaDB 10.6✗ 135610.11✗ 135611.4✗ 135611.8✗ 1356
✓works ✓ 1062fails with the error the step demonstrates ⚠works with a warning ≠runs, result differs ✗fails Tested 2026-11-23 on 5.6.51, 5.7.44, 8.0.46, 8.4.13, 9.7.4, 10.6.28, 10.11.19, 11.4.13, 11.8.9
What the warnings and failures say (3)
  • LOAD DATA INFILE '/tmp/product.csv' as root (original path) (MySQL 5.6, MySQL 5.7, MySQL 8.0, MySQL 8.4, MySQL 9): error 1290: The MySQL server is running with the --secure-file-priv option so it cannot execute this statement
  • UPDATE mysql.user SET File_priv = 'Y' + FLUSH PRIVILEGES (original alternative) (MySQL 9): warning 1681: 'FLUSH PRIVILEGES' is deprecated and will be removed in a future release.
  • UPDATE mysql.user SET File_priv = 'Y' + FLUSH PRIVILEGES (original alternative) (MariaDB 10.6, MariaDB 10.11, MariaDB 11.4, MariaDB 11.8): error 1356: View 'mysql.user' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them

Related errors: 1045, 1290, 1356

The original article

First published 2011-03-02. The text below is the original; the table above shows how it behaves on current versions.

Loading data from a file directly into a table is one of the nice features of MySQL. However, before this can be done we need to make sure that the correct permissions are assigned to the user performing the import. Otherwise the process will fail with the following error message:

mysql> LOAD DATA INFILE '/tmp/product.csv' INTO TABLE name LINES TERMINATED BY '\n';
ERROR 1045 (28000): Access denied for user 'user'@'localhost' (using password: NO)

The error indicates that the user does not have the appropriate permission to perform this kind of operation. The LOAD DATA INFILE is controlled by the FILE global privileges. These are privileges that are not directly assigned on a database or table basis but on the MySQL server level.

To grant a global privilege we need to specify ’.’ rather than ‘{database}.{table}’ that is common for INSERT, UPDATE, SELECT, DELETE privileges. The ’*’ indicates all.

So in the case above we need to perform the following command as a privileged user (root).

GRANT FILE ON *.* TO user@localhost;

An alternative way of performing the same operation involves updating one of the MySQL server tables as follows:

UPDATE mysql.user SET File_priv = 'Y' WHERE Host = 'localhost' AND User = 'user';
FLUSH PRIVILEGES;