Home  >  Article  >  Database  >  How to Fix \"Access Denied\" Errors When Using LOAD DATA INFILE in MySQL?

How to Fix \"Access Denied\" Errors When Using LOAD DATA INFILE in MySQL?

Barbara Streisand
Barbara StreisandOriginal
2024-10-31 05:48:02269browse

How to Fix

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn