【mysql】 mysql忘记密码

时间:2024-01-20 15:45:15

先关闭mysql服务

[root@localhost ~]# service mysql status
Redirecting to /bin/systemctl status mysql.service
● mysql.server.service - LSB: start and stop MySQL
Loaded: loaded (/etc/rc.d/init.d/mysql.server; bad; vendor preset: disabled)
Active: inactive (dead) since 四 -- :: CST; 1min 51s ago
Docs: man:systemd-sysv-generator()
Process: ExecStop=/etc/rc.d/init.d/mysql.server stop (code=exited, status=/SUCCESS)
Process: ExecStart=/etc/rc.d/init.d/mysql.server start (code=exited, status=/SUCCESS)

用mysqld_safe启动mysql,并--skip-grant-tables跳过权限的审核。

[root@localhost ~]# mysqld_safe --skip-grant-tables &   

登录

[root@localhost ~]# mysql --user=root mysql

这样就能进入mysql环境中,修改用户密码。将root用户密码设置为111111

mysql> update user set authentication_string=PASSWORD('') WHERE User='root';

刷新下权限

mysql> flush privileges;
Query OK, rows affected (0.06 sec) mysql> QUIT;

然后用新密码登录就可以进入

[root@localhost ~]# mysql -uroot -p111111