假如Mysql忘记密码,或者在初次安装Mysql时忘记密码,如何修改密码呢,这时就需要用到mysql的参数配置 skip-grant-tables。
- 修改my.cnf
加上参数 skip-grant-tables

 - 重启mysql服务
 - 输入命令行登录
 
mysql -uroot -p
 
不用输入密码,直接回车即可登录
- 进行密码修改
 
sql>alter user 'root'@'localhost' identified by 'root123';
sql>grant all privileges on *.* to'root'@'%' identified by 'root123';
sql>flush privileges;
sql>exit
 
- 重新回到第一步把skip-grant-tables去除,重启mysql服务,用新密码登录即可
 - 常见问题
 
-  执行修改密码出错
执行语句:alter user ‘root’@‘localhost’ identified by ‘root123’
错误信息:ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
解决方案: 
sql>flush privileges;
 
再重新往下执行即可










