Home >Database >Mysql Tutorial >How to Fix \'Access Denied\' Errors When Using LOAD DATA INFILE in MySQL?
Troubleshooting Access Denied Errors for LOAD DATA INFILE Operation in MySQL
When executing a LOAD DATA INFILE query in MySQL using PHP, encountering the error "Access denied for user 'user'@'localhost' (using password: YES)" can arise. This signifies that the user lacks the necessary privileges to perform the operation.
To rectify this issue, it is essential to grant the user the FILE privilege. By adding the keyword LOCAL to the LOAD DATA INFILE statement, this privilege is implicitly granted.
Example:
To demonstrate, consider the following statement that causes the access denied error:
LOAD DATA INFILE 'file_name.csv' INTO TABLE table_name;
To correct this statement and enable the operation, simply add LOCAL to the query:
LOAD DATA LOCAL INFILE 'file_name.csv' INTO TABLE table_name;
By making this modification, the user will be granted temporary FILE privileges, allowing the data loading operation to proceed without encountering any permission-related errors.
The above is the detailed content of How to Fix \'Access Denied\' Errors When Using LOAD DATA INFILE in MySQL?. For more information, please follow other related articles on the PHP Chinese website!