一、 先关闭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
+-----------+------------------+---------------------------+