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号