一、 先關閉mysql服務
關閉命令:
mysql.server stop
啓動命令爲:
mysql.server start
二、 進入安全模式
mysqld --skip-grant-tables
之後這個窗口就不能輸入命令。
三、登錄
輸入:
mysql -u root -p
隨便輸入密碼就可以登錄了。
四、查看用戶表信息
輸入:
use mysql
desc user;
看看密碼字段,password不存在就是authentication_string(高版本)
五、查看用戶密碼
輸入:
select host, user, authentication_string from user;
結果:
+-----------+------------------+--------------------------+
| Host | User | authentication_string
+-----------+------------------+------------------------+
| localhost | mysql.infoschema | 123
| localhost | mysql.session | 123
| localhost | mysql.sys | 123
| localhost | root | 123
+-----------+------------------+---------------------------+