[root@db04 ~]# systemctl stop mysqld
[root@db04 ~]# mysqld_safe --skip-grant-table & #跳过授权表,直接就可以登录mysql
注:一个非常有用的mysql启动参数—— --skip-grant-tables。顾名思义,就是在启动
mysql时不启动grant-tables,授权表 --skip-networking是不让别的用户远程登陆
[root@db02 scripts]# mysql #登录MySQL
#往mysql库的user表中插入root用户
mysql> grant all on . to root@'localhost'; #这条命令不需要执行,直接执行下面的命令
mysql> flush privileges;
在数据库里执行,把以下的内容粘贴复制进去
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');
[root@db02 scripts]# mysqladmin -uroot -p1 shutdown
[root@db02 scripts]# systemctl restart mysqld
[root@db02 scripts]# mysql
转载于:https://blog.51cto.com/13523963/2344348