停止mysql
[root@warybee ~]# /etc/init.d/mysqld stop
##忽略授权验证启动MySQL
[root@warybee ~]# mysqld_safe --skip-grant-tables --user=mysql &
使用mysql命令匿名登录
[root@warybee ~]# mysql
##修改密码
mysql5.6及以下:
mysql> update mysql.user set password=password("要修改的密码") where user='root';
mysql5.7:
mysql> update mysql.user set authentication_string=password(“要修改的密码”) where user=‘root’;
刷新权限
mysql> flush privileges;
停止MySQL
密码已经重置过了,接下来就要停止刚才忽略授权启动的mysql,命令如下:
[root@warybee ~]# [root@warybee ~]# mysqladmin -uroot -p123 shutdown
注:-p后面是你刚刚修改的密码
重新启动MySQL
[root@warybee ~]# /etc/init.d/mysqld start