MySQL Access Denied for Non-Root User
The problem you're encountering when attempting to log in as a non-root user stems from insufficient permissions granted to the user. While the steps you outlined for user creation appear correct, granting all privileges on all databases is a security concern.
Solution
Instead of granting all privileges to a non-root user, use more specific permissions. Use the following syntax:
GRANT <privileges> ON database.* TO 'user'@'localhost' IDENTIFIED BY 'password';
For example, to provide an example, grant specific privileges for data manipulation:
GRANT INSERT, SELECT, DELETE, UPDATE ON database.* TO 'user'@'localhost' IDENTIFIED BY 'password';
Additional Information
To view the privileges granted to users, execute the following query as the "root" user:
select Host, User from mysql.user;
This will provide insights into the privileges granted to different users.
The above is the detailed content of Why Is My MySQL Non-Root User Access Denied, and How Can I Fix It?. For more information, please follow other related articles on the PHP Chinese website!