1、修改my.cnf
vi /etc/my.cnf
在配置文件中加入
skip-grant-tables
保存退出
2、重启mysql
service mysqld restart
3、登录
mysql -u root -p
直接回车,即可免密登录,对密码进行置空
use mysql
update user set authentication_string = '' where user = 'root';
4、将skip-grant-tables注释掉,重启mysql
5、修改密码
alter user 'root'@'localhost' identified by '新的密码'
密码符合字母大小写、数字及特殊符号,但是密码并没有修改成功
查看user及host
select user,host from user;
root对应的host并不是localhost,而是%
重新修改密码
alter user 'root'@'%' identified by '新的密码'
修改成功,重新启动mysql