只支持rocky linux9.3,但是其他版本也差不多。

确定linux的版本

[root@Server33 ~]# cat /etc/os-release 
NAME="Rocky Linux"
VERSION="9.3 (Blue Onyx)"
ID="rocky"
ID_LIKE="rhel centos fedora"
VERSION_ID="9.3"
PLATFORM_ID="platform:el9"
PRETTY_NAME="Rocky Linux 9.3 (Blue Onyx)"
ANSI_COLOR="0;32"
LOGO="fedora-logo-icon"
CPE_NAME="cpe:/o:rocky:rocky:9::baseos"
HOME_URL="https://rockylinux.org/"
BUG_REPORT_URL="https://bugs.rockylinux.org/"
SUPPORT_END="2032-05-31"
ROCKY_SUPPORT_PRODUCT="Rocky-Linux-9"
ROCKY_SUPPORT_PRODUCT_VERSION="9.3"
REDHAT_SUPPORT_PRODUCT="Rocky Linux"
REDHAT_SUPPORT_PRODUCT_VERSION="9.3"

添加yum源和导入密钥

[root@Server33 ~]# dnf install https://dev.mysql.com/get/mysql80-community-release-el9-3.noarch.rpm -y
Last metadata expiration check: 0:18:48 ago on Sun May 31 18:43:09 2026.
mysql80-community-release-el9-3.noarch.rpm                                                                                    4.3 kB/s |  10 kB     00:02    
Package mysql80-community-release-el9-3.noarch is already installed.
Dependencies resolved.
Nothing to do.
Complete!
[root@Server33 ~]# rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2023
[root@Server33 ~]# 

生成一下yum缓存

[root@Server33 ~]# yum makecache 
Docker CE Stable - x86_64                                                                                                      16 kB/s | 2.0 kB     00:00    
Extra Packages for Enterprise Linux 9 - x86_64                                                                                 13 kB/s |  10 kB     00:00    
Extra Packages for Enterprise Linux 9 openh264 (From Cisco) - x86_64                                                          1.2 kB/s | 993  B     00:00    
MySQL 8.0 Community Server                                                                                                    4.9 kB/s | 3.0 kB     00:00    
MySQL Connectors Community                                                                                                    4.9 kB/s | 3.0 kB     00:00    
MySQL Tools Community                                                                                                         4.9 kB/s | 3.0 kB     00:00    
Rocky Linux 9 - BaseOS                                                                                                         38 kB/s | 4.3 kB     00:00    
Rocky Linux 9 - AppStream                                                                                                      40 kB/s | 4.8 kB     00:00    
Rocky Linux 9 - Extras                                                                                                         27 kB/s | 3.1 kB     00:00    
wlnmp                                                                                                                          24 kB/s | 2.9 kB     00:00    
Metadata cache created.
[root@Server33 ~]# 

安装mysql:8.0

[root@Server33 ~]# dnf install -y mysql-community-server
Last metadata expiration check: 0:01:37 ago on Sun May 31 19:03:18 2026.
Package mysql-community-server-8.0.46-1.el9.x86_64 is already installed.
Dependencies resolved.
Nothing to do.
Complete!
[root@Server33 ~]# 
  • 启动mysql

  • 设置开机自启

  • 查看mysql的初始密码

  • 重置mysql root 用户的密码

[root@Server33 ~]#  systemctl enable --now mysqld.service
[root@Server33 ~]# ss -tnl
State             Recv-Q            Send-Q                        Local Address:Port                          Peer Address:Port            Process            
LISTEN            0                 128                                 0.0.0.0:22                                 0.0.0.0:*                                  
LISTEN            0                 151                                       *:3306                                     *:*                                  
LISTEN            0                 128                                    [::]:22                                    [::]:*                                  
LISTEN            0                 70                                        *:33060                                    *:*                                  
[root@Server33 ~]# 

[root@Server33 ~]# grep 'password' /var/log/mysqld.log
2026-05-31T10:20:56.985559Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: yiaigsY#f7tn
[root@Server33 ~]# 

ALTER USER 'root'@'localhost' IDENTIFIED BY '新密码';
FLUSH PRIVILEGES;

设置完成之后在重新登录一下,进行一下验证。

[root@Server33 ~]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.46 MySQL Community Server - GPL

Copyright (c) 2000, 2026, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 
mysql> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

mysql> 

OK 完美