Home >Database >Mysql Tutorial >Why Am I Getting 'Access denied for user 'root'@'localhost'' When Granting Privileges?

Why Am I Getting 'Access denied for user 'root'@'localhost'' When Granting Privileges?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-12-10 07:34:13929browse

Why Am I Getting

Unable to Grant Privileges as 'root'

When attempting to grant privileges as the root user with all necessary permissions, you may encounter the error "Access denied for user 'root'@'localhost.'" This issue arises when you try to grant privileges on the off-limits mysql.users table.

Solution:

To resolve this problem, grant privileges on a specific database instead of all tables. Use the following syntax:

GRANT ALL PRIVILEGES ON `%`.* TO '[user]'@'[hostname]' IDENTIFIED BY '[password]' WITH GRANT OPTION;

Here, % represents any database, and you can specify the database name in place of the asterisk (*). This approach excludes the mysql.users table from the privileges, allowing you to grant privileges to other users.

The above is the detailed content of Why Am I Getting 'Access denied for user 'root'@'localhost'' When Granting Privileges?. 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