Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

access denied for load data infile in MySQL

People also ask

How do I fix access denied in MySQL?

To resolve the error, you must create a user with the following command: mysql> GRANT ALL ON *. * to user_name@localhost IDENTIFIED BY 'password'; Replace user_name with the user's username and password with the user's password.

How do I enable local data loading in MySQL?

To disable or enable it explicitly, use the --local-infile=0 or --local-infile[=1] option. For the mysqlimport client, local data loading is not used by default. To disable or enable it explicitly, use the --local=0 or --local[=1] option.

What is load data infile?

The LOAD DATA INFILE statement reads rows from a text file into a table at a very high speed. If the LOCAL keyword is specified, the file is read from the client host. If LOCAL is not specified, the file must be located on the server. ( LOCAL is available in MySQL 3.22.

Which privilege is often used when loading a file into a database table?

The grant privilege allows you to give to other users those privileges you possess. The file privilege gives you permission to read and write files on the server using the LOAD DATA INFILE and SELECT ... INTO OUTFILE statements.


I just ran into this issue as well. I had to add LOCAL to my SQL statement.

For example, this gives the permission problem:

LOAD DATA INFILE '{$file}' INTO TABLE {$table}

Add LOCAL to your statement and the permissions issue should go away. Like so:

LOAD DATA LOCAL INFILE '{$file}' INTO TABLE {$table}

I had this problem. I searched around and did not find a satisfactory answer. I summarise below the results of my searches.

The access denied error could mean that:

  • 'user'@'localhost' does not have the FILE privilege (GRANT FILE on *.* to user@'localhost'); or,
  • the file you are trying to load does not exist on the machine running mysql server (if using LOAD DATA INFILE); or,
  • the file you are trying to load does not exist on your local machine (if using LOAD DATA LOCAL INFILE); or,
  • the file you are trying to load is not world readable (you need the file and all parent directories to be world-readable: chmod 755 directory; and, chmod 744 file.dat)

Try using this command:

load data local infile 'home/data.txt' into table customer;

This should work. It worked in my case.


Ensure your MySQL user has the FILE privilege granted.

If you are on shared web hosting, there is a chance this is blocked by your hosting provider.


I found easy one if you are using command line

Login asmysql -u[username] -p[password] --local-infile

then SET GLOBAL local_infile = 1;

select your database by use [db_name]

and finally LOAD DATA LOCAL INFILE 'C:\\Users\\shant\\Downloads\\data-1573708892247.csv' INTO TABLE visitors_final_test FIELDS TERMINATED BY ','LINES TERMINATED BY '\r \n' IGNORE 1 LINES;