ubuntu25.10安裝mysql,設置root密碼
一、ubuntu25.10可直接安裝mysql,此時無法用root密碼進入mysql,可使用sudo進入;
sudo apt update
sudo apt install mysql-server
sudo mysql
[sudo: authenticate] Password: .... Your MySQL connection id is 8 Server version: 8.4.6-0ubuntu3 (Ubuntu) .....
二、mysql_secure_installation 一樣使用sudo;
sudo mysql_secure_installation
按提示進行安全設置。
三、默認情況下,mysql使用auth_socket進入root用戶認證(這是root用戶無法用密碼進入的原因),
MySQL服務器也啟用了caching_sha2_password插件;
mysql> use mysql mysql> select user,authentication_string,plugin from user;
+------------------+------------------------------------------------------------------------+-----------------------+
| user | authentication_string | plugin | +------------------+------------------------------------------------------------------------+-----------------------+ | debian-sys-maint | root | auth_socket | | mysql.infoschema | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password | | mysql.session | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password | | mysql.sys | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password | | root | | auth_socket | +------------------+------------------------------------------------------------------------+-----------------------+ 5 rows in set (0.00 sec)
四、我們需將root認證方式改為caching_sha2_password方式,并用此方式設置root密碼;
mysql> update user set plugin='caching_sha2_password' where user='root'; mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'your_password'; mysql> select user,authentication_string,plugin from user;
+------------------+------------------------------------------------------------------------+-----------------------+
| user | authentication_string | plugin |
+------------------+------------------------------------------------------------------------+-----------------------+
| debian-sys-maint | root | auth_socket |
| mysql.infoschema | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
| mysql.session | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
| mysql.sys | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
| root | $A$005$?HAqF#gtm}+
d,0ST46h11SEo0IioxCHTmZ.9cjqRml6aD1jM6FRC7uCA | caching_sha2_password |
+------------------+------------------------------------------------------------------------+-----------------------+
5 rows in set (0.00 sec)
五、成功
mysql> exit; ~$ mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 11 Server version: 8.4.6-0ubuntu3 (Ubuntu)
...
完成。
浙公網安備 33010602011771號