安装mysql后无法找到临时密码的解决方案
一、环境
系统:CentOS7
mysql:5.7.20
二、解决步骤
step1:修改/etc/my.cnf
添加:
skip-grant-tables
![](https://upload-images.jianshu.io/upload_images/1324962-8ef8f16bdc529111.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/697/format/webp)
step2:重启mysql
service mysqld restart
step3:登录
mysql -u root #此时不需要密码,可以直接登录
step4:修改密码
update mysql.user set password=password('root') where user='root';
![](https://upload-images.jianshu.io/upload_images/1324962-7cd9db94b86a0847.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/615/format/webp)
step5:清除并退出
flush privileges;
![](https://upload-images.jianshu.io/upload_images/1324962-94a25a5bf32a277b.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/340/format/webp)
step6:修改my.cnf
把step1添加的内容删除
![](https://upload-images.jianshu.io/upload_images/1324962-1e4e210539a53879.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/661/format/webp)
step7:重启mysql
service mysqld restart
此时登录输入设置的密码就可以了。
登录成功:
![](https://upload-images.jianshu.io/upload_images/1324962-ed47e3229e94dfb6.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/650/format/webp)