"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > Why Am I Getting \"Access Denied\" When Connecting to MySQL Despite Creating a New User With Privileges?

Why Am I Getting \"Access Denied\" When Connecting to MySQL Despite Creating a New User With Privileges?

Published on 2024-11-07
Browse:466

Why Am I Getting \

MySQL - Access Denied for User

Despite creating a new user with the necessary privileges, you may encounter the "Access denied" error when attempting to connect to the database. This issue arises due to an incorrect grant statement.

The error message indicates that the user 'servname_shb'@'localhost' does not have access to the database. To rectify this, use the following grant statement:

GRANT ALL ON *.* TO 'servname_shb'@'localhost';

This grants the specified user full access to all databases and tables on the local host. Alternatively, you can limit the access to only the required components by specifying specific databases or tables in the grant statement.

For example, to grant access to the 'servname_shbusers' database only:

GRANT ALL ON servname_shbusers TO 'servname_shb'@'localhost';

To further secure the database, it is recommended to limit the user's access to only the necessary privileges. Using the GRANT statement with specific privileges allows you to restrict the user's ability to perform certain actions, such as creating, altering, or deleting data.

Latest tutorial More>

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