初始密碼查看
初始密碼在“mysqld.log”日志里胃榕,mysqld.log的路徑在my.cnf(/etc/my.cnf)里面可以查看
使用初始化密碼姻采,登錄修改密碼(強(qiáng)制的,必須修改)
>mysql -u root -p
Enter password:
mysql>ALTER user 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'xxxxx';
修改root用戶(hù)密碼(不查看日志擦酌,直接修改)
關(guān)閉mysql服務(wù)
systemctl stop mysqld.service
修改密碼
修改配置 /etc/my.cnf 增加 skip-grant-tables(免密登錄)
vi /etc/my.cnf
啟動(dòng)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: