Mysql8初始密碼查看&修改root用戶密碼(linux)

初始密碼查看

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

image.png

使用初始化密碼,登錄修改密碼(強(qiáng)制的,必須修改)
>mysql -u root -p
Enter password:
mysql>ALTER user 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'xxxxx';


修改root用戶密碼(不查看日志,直接修改)

關(guān)閉mysql服務(wù)

systemctl stop mysqld.service

修改密碼

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

image.png

啟動mysql服務(wù)

systemctl start mysqld.service

免密登錄,置空密碼(authentication_string或者password)

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

恢復(fù)配置文件(注釋掉或者刪掉 skip-grant-tables),重啟mysql服務(wù)

>systemctl restart mysqld.service

重新免密登錄,修改密碼(authentication_string或者password)

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

驗(yàn)證結(jié)果,輸入剛剛的密碼登錄

>mysql -u root -p
Enter password:

image.png

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容