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:
GRANT FILE ON *.* TO user_name;
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:
LOAD DATA LOCAL INFILE 'path/to/file.csv' INTO TABLE table_name;
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3