- 停止mysqld; sudo /etc/init.d/mysql stop (您可能有其它的方法,总之停止mysqld的运行就可以了)
- 用以下命令启动MySQL,以不检查权限的方式启动; mysqld –skip-grant-tables &
- 然后用空密码方式使用root用户登录 MySQL; mysql -u root
- 修改root用户的密码; mysql> update mysql.user set password=PASSWORD(‘newpassword’) where User=’root’; mysql> flush privileges; mysql> quit 重新启动MySQL /etc/init.d/mysql restart 就可以使用新密码 newpassword 登录了。
8.0版本
已有密码:
use mysql;
update user set authentication_string=” where user=’root’;–将字段置为空
ALTER user ‘root’@’localhost’ IDENTIFIED BY ‘root’;–修改密码为root
密码为空:
ALTER user ‘root’@’localhost’ IDENTIFIED BY ‘root’;–修改密码为root
低调的飘过