Home > Database > Mysql Tutorial > 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?

Susan Sarandon
Release: 2024-10-31 08:04:02
Original
944 people have browsed it

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:

<code class="sql">GRANT ALL ON *.* TO 'servname_shb'@'localhost';</code>
Copy after login

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>
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template