美文网首页
Mysql8初始密码查看&修改root用户密码(linux)

Mysql8初始密码查看&修改root用户密码(linux)

作者: RookieSnail | 来源:发表于2019-12-12 14:42 被阅读0次

初始密码查看

初始密码在“mysqld.log”日志里,mysqld.log的路径在my.cnf(/etc/my.cnf)里面可以查看

image.png
使用初始化密码,登录修改密码(强制的,必须修改)
>mysql -u root -p
Enter password:
mysql>ALTER user 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'xxxxx';

修改root用户密码(不查看日志,直接修改)

关闭mysql服务

systemctl stop mysqld.service

修改密码

修改配置 /etc/my.cnf 增加 skip-grant-tables(免密登录)
vi /etc/my.cnf

image.png
启动mysql服务

systemctl start mysqld.service

免密登录,置空密码(authentication_string或者password)

>mysql
mysql>use mysql;
mysql>update user set authentication_string=null where user='root';
mysql>quit;

恢复配置文件(注释掉或者删掉 skip-grant-tables),重启mysql服务

>systemctl restart mysqld.service

重新免密登录,修改密码(authentication_string或者password)

>mysql
mysql>ALTER user 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'xxxxx';
mysql>quit;

验证结果,输入刚刚的密码登录

>mysql -u root -p
Enter password:

image.png

相关文章

网友评论

      本文标题:Mysql8初始密码查看&修改root用户密码(linux)

      本文链接:https://www.haomeiwen.com/subject/nyhtnctx.html