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
Release: 2024-12-27 01:56:15
Original
540 people have browsed it

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

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

Additional Information

To view the privileges granted to users, execute the following query as the "root" user:

select Host, User from mysql.user;
Copy after login

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!

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