首页 > 技术文章 > linux 下mysql忘记密码或者安装好linux后不知道mysql初始密码解决方案

zhf123 2019-12-13 14:37 原文

1、使用yum安装mysql后
2、初始密码在/var/log/mysqld.log这个文件里
3、输入命令:grep 'temporary password' /var/log/mysqld.log,可以直接获取密码。
(注:密码为冒号后面的所有字符!)
如果想要更换初始密码,可以按照下面的操作。
在/etc/my.cnf中加入如下内容:
在[mysqld]下添加skip-grant-tables,然后保存并退出

然后重启mysql服务
systemctl restart mysqld
a、重启以后,执行mysql命令进入mysql命令行

b、修改root用户密码

MySQL> update mysql.user set authentication_string=password('123456') where user='root';
MySQL> flush privileges;
MySQL> exit

c、最后把/etc/my.cnf中的skip-grant-tables注释掉,然后重启mysql,即:service mysqld restart

OK,下面我们就可以使用root新的密码登录MySQL了。

参考链接:
https://blog.csdn.net/wohiusdashi/article/details/89358071
https://www.cnblogs.com/whoyoung/p/10987005.html

推荐阅读