MySQL8报错:Access denied for user ‘root‘@‘%‘ to database ‘myTest‘

今天突然遇到一个来自Mysql8的报错:Access denied for user 'root'@'%' to database 'myTest',就是可以通过远程链接数据库,但是无法创建,修改,删除等等数据库操作,很奇怪.

于是我看了很多的博客,
有的博客说:GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
有的说:GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '你的密码' WITH GRANT OPTION;
但是都解决不了问题:


于是细想,这个问题不正是因为root用户突然失去了数据库操控的权限嘛,我们可以把权限都设置为Y:
update user set Select_priv ='Y' where user = 'root';

update user set Insert_priv ='Y' where user = 'root';

update user set Update_priv ='Y' where user = 'root';

update user set Delete_priv ='Y' where user = 'root';

update user set Create_priv ='Y' where user = 'root';

update user set Drop_priv ='Y' where user = 'root';

update user set Reload_priv ='Y' where user = 'root';

update user set Shutdown_priv ='Y' where user = 'root';

update user set Process_priv ='Y' where user = 'root';

update user set File_priv ='Y' where user = 'root';

update user set Grant_priv ='Y' where user = 'root';

update user set References_priv ='Y' where user = 'root';

update user set Index_priv ='Y' where user = 'root';

update user set Alter_priv ='Y' where user = 'root';

update user set Show_db_priv ='Y' where user = 'root';

update user set Super_priv ='Y' where user = 'root';

update user set Create_tmp_table_priv ='Y' where user = 'root';

update user set Lock_tables_priv ='Y' where user = 'root';

update user set Execute_priv ='Y' where user = 'root';

然后再刷新重启MySQL:

flush privileges;
service mysql restart

终于恢复正常了。。。遂记录下解决的过程。

你可能感兴趣的:(Java开发,数据库,linux,前端)