1.使用命令“vi /etc/my.cnf”文件
2.在[mysqld]最下面添加“skip-grant-tables”,跳过权限的检查
3.输入“systemctl start mysqld"重启mysqld
4.登录MySQL服务“mysql -uroot -p”
5.使用命令 "ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '你的密码' "修改密码。
6.使用命令“flush privileges”更新
7.最后,输入exit退出mysql,然后按照步骤一输入“vi /etc/my.cnf”进入配置文件给“skip-grant-tables”给它前面加上#将其注释掉就好了!
8.简单的修改不同版本的密码,以下为5.7版本和8.0版本
如果你使用的是MySQL 8.0版本,应该使用以下命令:
update user set authentication_string=password('your_new_password') where user='root';
如果你使用的是MySQL 5.7版本,应该使用以下命令:
update user set password=PASSWORD('your_new_password') where User='root'