服务器数据库密码忘记

原因

  • 数据库连接报错

解决方案

  • 绕过数据库密码登录

步骤

vi /etc/my.cnf

在[mysqld]的段中加上一句:skip-grant-tables ;保存并且退出vi,并重启mysql 如图:

重新启动mysql之后

password变成了authentication_string 
mysql>  update user set authentication_string = password("123456") where user='root';
mysql> flush privileges; 
mysql> quit 

删除刚刚添加的配置,重启数据库后再使用新的密码登录

  • 删除 skip-grant-tables
原文地址:https://www.cnblogs.com/nikeodong/p/8243398.html