mysql user表root 用户误删除解决方法


1、先以root用户登录系统;

2、关闭mysql服务:/etc/init.d/mysql stop;

3、特权启动mysql:/usr/local/mysql/bin/mysqld_safe --user=mysql --skip-grant-tables --skip-networking &(注:参数--skip-grant-tables为跳过授权表)

4、登录跳过授权表的数据库:#mysql -uroot -h localhost

5、查看user表:mysql> select Host,User,Password from mysql.user;

6、插入root表:mysql> INSERT INTO mysql.user (Host,User,Password,ssl_cipher,x509_issuer,x509_subject,authentication_string) VALUES('localhost', 'root',password('123456'),'','','','');

7、在root表添加root的所有权限:

1) 查询权限

select * from mysql.user where user='root' and host='localhost'\G

2) update mysql.user set Select_priv='Y',Insert_priv='Y',Update_priv='Y',Delete_priv='Y',Create_priv='Y',Drop_priv='Y',Reload_priv='Y',Sh='Y',Shutdown_priv='Y',Process_priv='Y',File_priv='Y',Grant_priv='Y',References_priv='Y',Index_priv='Y',Alter_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',Event_priv='Y',Trigger_priv='Y',Create_tablespace_priv='Y' where User='root' and Host='localhost';

3)验证权限

select * from mysql.user where user='root' and host='localhost'\G

8、交&刷新权限

commit;

flush prvilileges;

9、重启mysql

[root@mysql ~]# /etc/init.d/mysqld restart

10、登录验证

mysql -u root -p

mysql> show grants;