Home >Database >Mysql Tutorial >Why Am I Getting 'Access denied for user 'root'@'localhost'' When Granting Privileges?
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!