背景:昨天很意外的发现自己网站的数据库连接出现问题了,登上服务器发现mysql状态已经是failed了,重启mysql后,又可以访问了。想连上数据库看看数据有没有什么问题,却发现密码忘了!!!
找到原来的博客,很快的又熟悉了修改密码的流程,但是怎么改都报错,配置文件my.cnf中添加skip-grant-tables后用alter ** 语句修改密码时报错,直接使用update mysql.user set password=password(‘newpassowrd’) where user=’root’;也是报错,经过种种尝试后,使用如下方法成功修改了密码。
(1)在配置文件my.cnf的[mysqld]中设置skip-grant-tables,重启mysql
(2)update mysql.user set authentication_string=” where user=’root’;
(3)删除配置文件中的skip-grant-tables,重启mysql
(4)重新连接mysql,alter user ‘root’@’localhost’ identified by ‘password’;