自己作死把root得权限全给去掉了,然后导致无法添加用户等其他操作,然后就想办法补救

1、修改mysql 配置文件,添加属性

vi /etc/my.conf  # 你的配置文件可能不在这 

skip-grant-tables  #添加这个属性,表示不校验权限密码等

2、重启mysql

service mysql restart

# 或者
systemctl restart mysql

3、进入mysql 客户端

3.1 进入mysql表

use mysql

3.2 授权

update user set Host='%',select_priv='y',insert_priv='y',update_priv='y',Alter_priv='y',delete_priv='y',create_priv='y',drop_priv='y',reload_priv='y',shutdown_priv='y',Process_priv='y',file_priv='y',grant_priv='y',References_priv='y',index_priv='y',create_user_priv='y',show_db_priv='y',super_priv='y',create_tmp_table_priv='y',Lock_tables_priv='y',execute_priv='y',repl_slave_priv='y',repl_client_priv='y',create_view_priv='y',show_view_priv='y',create_routine_priv='y',alter_routine_priv='y',create_user_priv='y' where user='root';

3.3 修改密码

5.7版本以前:

update mysql.user set password=password('root') where user='root';

5.7及以上:

update mysql.user set authentication_string=password('root') where user='root';

其他更改密码方式:

set password for root@localhost = password('123456');
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
ALTER USER 'root'@'localhost' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER;

4、刷新

flush privileges;

5、删掉第一步添加的属性 然后重启。

posted on 2021-12-28 16:24  java先生  阅读(169)  评论(0编辑  收藏  举报