Home >Database >Mysql Tutorial >Why Is My MySQL Non-Root User Access Denied, and How Can I Fix It?

Why Is My MySQL Non-Root User Access Denied, and How Can I Fix It?

Linda Hamilton
Linda HamiltonOriginal
2024-12-27 01:56:15667browse

Why Is My MySQL Non-Root User Access Denied, and How Can I Fix It?

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!

Statement:
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