mysql版本为5.7.22mysql
1.修改my.cnf文件sql
添加一行centos
skip-grant-tables=1
保存退出。bash
2. 停掉mysql服务。centos7
3. 运行登录命令.net
mysql -u root
4. 修改密码code
mysql -u root; update user set authentication_string = password('${yourPassword}'),password_last_changed=now() where user='root';
${yourPasswor}你的新密码。blog
5. 删除my.cnf里的skip-grant-tables=1ip
6.重启mysqlget
7.进入mysql从新修改密码。
步骤见centos7.5下mysql5.7.22安装,与里面的密码设置同样便可。