初始密碼查看
初始密碼在“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