Access Denied for LOAD DATA INFILE in MySQL
In MySQL, using the LOAD DATA INFILE statement may result in an access denied error, such as "#1045 - Access denied for user 'user'@'localhost' (using password: YES)."
This error typically indicates that the current user executing the query does not have sufficient privileges to load data from a file into a table. To resolve this issue, ensure that the user has the necessary permissions.
In particular, the user needs to be granted the FILE privilege. This privilege allows users to read files from the server's file system. Without this privilege, the user will not be able to access the specified file.
To grant the FILE privilege to a user, execute the following query:
<code class="sql">GRANT FILE ON *.* TO user_name;</code>
Replace user_name with the username of the user to whom you want to grant the privilege.
Additionally, consider adding the LOCAL keyword to the LOAD DATA INFILE statement. The LOCAL keyword instructs MySQL to read the file from the client machine instead of the server's file system. This can be more efficient and secure in some cases.
Here's an example of a modified statement using LOCAL:
<code class="sql">LOAD DATA LOCAL INFILE 'path/to/file.csv' INTO TABLE table_name;</code>
The above is the detailed content of Why Am I Getting \'Access Denied\' When Using LOAD DATA INFILE in MySQL?. For more information, please follow other related articles on the PHP Chinese website!