误删除MySQL用户导致无法进入数据库
一.方法一
1.停止数据库
[root@db02 ~]# /etc/init.d/mysqld stop
2.跳过授权表,跳过网络启动数据库
[root@db02 ~]# mysqld_safe --skip-grant-tables --skip-networking &
3.连接数据库
[root@db02 ~]# mysql
4.插入新的root用户
insert into mysql.user values ('localhost','root',PASSWORD('123'),'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0,'mysql_native_password','','N');
5.重新启动MySQL
[root@db01 ~]# mysqladmin shutdown
[root@db01~]# /etc/init.d/mysqld start
Starting MySQL. SUCCESS!
二.方法2
1.停止数据库
[root@db02 ~]# /etc/init.d/mysqld stop
2.跳过授权表,跳过网络启动数据库
[root@db02 ~]# mysqld_safe --skip-grant-tables --skip-networking &
3.连接数据库
[root@db02 ~]# mysql
4.刷新授权表
mysql> flush privileges;
5.创建root超级用户
mysql> grant all on *.* to root@'localhost' identified by '123' with grant option;
6.重启数据库
[root@db01 ~]# mysqladmin -uroot -p123 shutdown;
[root@db01~]# /etc/init.d/mysqld start
三.方法3(前提是数据库没有数据)
1.停止数据库
[root@db02 ~]# /etc/init.d/mysqld stop
2.删文件
[root@db02 ~]# rm -rf /application/mysql/data/
3.初始化环境
[root@db02 ~]#./mysql_install_db --user=mysql --basedir=/application/mysql --datadir=/application/mysql/data
4.启动mysq
[root@db02 scripts]# /etc/init.d/mysqld start