[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