初始密码查看
初始密码在“mysqld.log”日志里,mysqld.log的路径在my.cnf(/etc/my.cnf)里面可以查看
使用初始化密码,登录修改密码(强制的,必须修改)
>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
启动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: