Home >Database >Mysql Tutorial >Why Am I Getting \'Access Denied\' When Connecting to MySQL Despite Creating a New User With Privileges?
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:
<code class="sql">GRANT ALL ON *.* TO 'servname_shb'@'localhost';</code>
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:
<code class="sql">GRANT ALL ON servname_shbusers TO 'servname_shb'@'localhost';</code>
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.
The above is the detailed content of Why Am I Getting 'Access Denied' When Connecting to MySQL Despite Creating a New User With Privileges?. For more information, please follow other related articles on the PHP Chinese website!