打开一个ssh
service mysqld stop #关闭mysql
/usr/bin/mysqld_safe --skip-grant-tables & #安全模式
打开另个ssh
mysql -u root -p
use mysql
select * from user where user='root' and host='localhost';#查看到root用户权限都变成N了。
执行下面的语句
update user set `Select_priv` = 'Y' where user='root' and host='localhost';
update user set `Insert_priv` = 'Y' where user='root' and host='localhost';
update user set `Update_priv` = 'Y' where user='root' and host='localhost';
update user set `Delete_priv` = 'Y' where user='root' and host='localhost';
update user set `Create_priv` = 'Y' where user='root' and host='localhost';
update user set `Drop_priv` = 'Y' where user='root' and host='localhost';
update user set `Reload_priv` = 'Y' where user='root' and host='localhost';
update user set `Shutdown_priv` = 'Y' where user='root' and host='localhost';
update user set `Process_priv` = 'Y' where user='root' and host='localhost';
update user set `File_priv` = 'Y' where user='root' and host='localhost';
update user set `Grant_priv` = 'Y' where user='root' and host='localhost';
update user set `References_priv` = 'Y' where user='root' and host='localhost';
update user set `Index_priv` = 'Y' where user='root' and host='localhost';
update user set `Alter_priv` = 'Y' where user='root' and host='localhost';
update user set `Show_db_priv` = 'Y' where user='root' and host='localhost';
update user set `Super_priv` = 'Y' where user='root' and host='localhost';
update user set `Create_tmp_table_priv` = 'Y' where user='root' and host='localhost';
update user set `Lock_tables_priv` = 'Y' where user='root' and host='localhost';
update user set `Create_tmp_table_priv` = 'Y' where user='root' and host='localhost';
update user set `Lock_tables_priv` = 'Y' where user='root' and host='localhost';
update user set `Execute_priv` = 'Y' where user='root' and host='localhost';
update user set `Repl_slave_priv` = 'Y' where user='root' and host='localhost';
update user set `Repl_client_priv` = 'Y' where user='root' and host='localhost';
update user set `Create_view_priv` = 'Y' where user='root' and host='localhost';
update user set `Show_view_priv` = 'Y' where user='root' and host='localhost';
update user set `Create_routine_priv` = 'Y' where user='root' and host='localhost';
update user set `Alter_routine_priv` = 'Y' where user='root' and host='localhost';
update user set `Create_user_priv` = 'Y' where user='root' and host='localhost';
update user set `Event_priv` = 'Y' where user='root' and host='localhost';
update user set `Trigger_priv` = 'Y' where user='root' and host='localhost';
update user set `Create_tablespace_priv` = 'Y' where user='root' and host='localhost';
然后执行flush privileges;
,让权限生效,然后执行命令service mysqld start
启动mysql即可
出现这个问题的原因是root用户密码应该严格按照阿里云linux环境mysql rpm安装中修密码更改说明
否则会将root用户的权限搞丢失。