先关闭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 四 2018-05-03 21:53:30 CST; 1min 51s ago Docs: man:systemd-sysv-generator(8) Process: 9580 ExecStop=/etc/rc.d/init.d/mysql.server stop (code=exited, status=0/SUCCESS) Process: 2417 ExecStart=/etc/rc.d/init.d/mysql.server start (code=exited, status=0/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('111111') WHERE User='root';
刷新下权限
mysql> flush privileges; Query OK, 0 rows affected (0.06 sec) mysql> QUIT;
然后用新密码登录就可以进入
[root@localhost ~]# mysql -uroot -p111111