- 修改vim /etc/my.cnf文件,在【mysqld】后添加skip-grant-tables(登入时时跳过检查)
skip-grant-tables
2.重启mysql服务
sudo systemctl restart mysqld
3.登入mysql,输入mysql -uroot -p,直接回车,登入进去,修改密码
update user set authentication_string="xiaoyang123" where user="root";
4.为避免麻烦,直接将远程访问也设置一下
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'IDENTIFIED BY 'xiaoyang123' WITH GRANT OPTION;
5.修改完成后输入quit;退出数据库,然后将my.cnf中的skip-grant-tables注释
6.重启mysql服务,service mysqld restart ,密码修改完成