解决mysql5.7忘记root密码
自建mysql5.7忘记root密码
环境:
os:centos7.8
解决步骤:
1)先关闭mysql
systemctl stop mysqld
2)然后查找到my.cnf,在[mysqld]下增加一段信息
[mysqld]
skip-grant-tables
3)启动mysql,登录,重置密码
systemctl start mysqld
mysql -u root
use mysql;
update mysql.user set authentication_string=password('C`ep.:bj?8p[2NT&') where user='root';
4)在my.cnf文件中,把刚才加入的那一行“skip-grant-tables”注释或删除掉。
然后重启MySQL服务后需要执行命令set password=password('newpassword');
set password=password('C`ep.:bj?8p[2NT&');