首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >MySQL包安装(一)

MySQL包安装(一)

原创
作者头像
用户11823619
发布2025-09-05 16:54:31
发布2025-09-05 16:54:31
5100
代码可运行
举报
运行总次数:0
代码可运行

2.2 包安装

2.2.1 Yum资源库安装MySQL

2.2.1.1 MySQL 8.0

在Rocky 8/9、Almalinux 8/9、CentOS Stream 8/9、openEuler 22.03/24.03 LTS、AnolisOS 8/23、OpenCloudOS 8/9、Kylin Server v10、UOS Server v20上安装MySQL:

代码语言:javascript
代码运行次数:0
运行
复制
[root@rocky9 ~]# yum list mysql-server --showduplicates
Last metadata expiration check: 0:00:27 ago on Fri 18 Apr 2025 08:58:40 PM CST.
Available Packages
mysql-server.x86_64                                     8.0.41-2.el9_5                                      appstream

[root@rocky9 ~]# yum install -y mysql-server

[root@rocky9 ~]# systemctl enable --now mysqld
Created symlink /etc/systemd/system/multi-user.target.wants/mysqld.service → /usr/lib/systemd/system/mysqld.service.

[root@rocky9 ~]# mysql -V
mysql  Ver 8.0.41 for Linux on x86_64 (Source distribution)

[root@rocky9 ~]# systemctl status mysqld
● mysqld.service - MySQL 8.0 database server
     Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; preset: disabled)
     Active: active (running) since Mon 2025-05-26 18:52:06 CST; 19s ago
    Process: 11774 ExecStartPre=/usr/libexec/mysql-check-socket (code=exited, status=0/SUCCESS)
    Process: 11796 ExecStartPre=/usr/libexec/mysql-prepare-db-dir mysqld.service (code=exited, status=0/SUCCESS)
   Main PID: 11870 (mysqld)
     Status: "Server is operational"
      Tasks: 38 (limit: 10892)
     Memory: 455.1M
        CPU: 3.566s
     CGroup: /system.slice/mysqld.service
             └─11870 /usr/libexec/mysqld --basedir=/usr

May 26 18:52:02 rocky9 systemd[1]: Starting MySQL 8.0 database server...
May 26 18:52:02 rocky9 mysql-prepare-db-dir[11796]: Initializing MySQL database
May 26 18:52:06 rocky9 systemd[1]: Started MySQL 8.0 database server.

[root@rocky9 ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.41 Source distribution

Copyright (c) 2000, 2025, 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'forhelp. Type '\c' to clear the current input statement.

mysql> status
--------------
mysql  Ver 8.0.41 for Linux on x86_64 (Source distribution)

Connection id:		8
Current database:	
Current user:		root@localhost
SSL:			Not in use
Current pager:		stdout
Using outfile:		''
Using delimiter:	;
Server version:		8.0.41 Source distribution
Protocol version:	10
Connection:		Localhost via UNIX socket
Server characterset:	utf8mb4
Db     characterset:	utf8mb4
Client characterset:	utf8mb4
Conn.  characterset:	utf8mb4
UNIX socket:		/var/lib/mysql/mysql.sock
Binary data as:		Hexadecimal
Uptime:			39 sec

Threads: 2  Questions: 5  Slow queries: 0  Opens: 120  Flush tables: 3  Open tables: 36  Queries per second avg: 0.128
--------------

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows inset (0.01 sec)

mysql> exit
Bye

复制

在CentOS 7上安装MySQL:

代码语言:javascript
代码运行次数:0
运行
复制
# centos7上镜像源默认没有mysql的安装包,需要添加镜像源
[root@centos7 ~]# cat > /etc/yum.repos.d/mysql.repo <<EOF
[mysql]
baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-8.0-community-el7-x86_64/
gpgcheck=0
EOF

[root@centos7 ~]# yum makecache

[root@centos7 ~]# yum list mysql-community-server --showduplicates
Loaded plugins: fastestmirror
Repository 'mysql' is missing name in configuration, using id
Loading mirror speeds from cached hostfile
Available Packages
mysql-community-server.x86_64                                 8.0.11-1.el7                                  mysql
mysql-community-server.x86_64                                 8.0.12-1.el7                                  mysql
mysql-community-server.x86_64                                 8.0.13-1.el7                                  mysql
mysql-community-server.x86_64                                 8.0.14-1.el7                                  mysql
mysql-community-server.x86_64                                 8.0.15-1.el7                                  mysql
mysql-community-server.x86_64                                 8.0.16-1.el7                                  mysql
mysql-community-server.x86_64                                 8.0.16-2.el7                                  mysql
mysql-community-server.x86_64                                 8.0.17-1.el7                                  mysql
mysql-community-server.x86_64                                 8.0.18-1.el7                                  mysql
mysql-community-server.x86_64                                 8.0.19-1.el7                                  mysql
mysql-community-server.x86_64                                 8.0.20-1.el7                                  mysql
mysql-community-server.x86_64                                 8.0.21-1.el7                                  mysql
mysql-community-server.x86_64                                 8.0.22-1.el7                                  mysql
mysql-community-server.x86_64                                 8.0.23-1.el7                                  mysql
mysql-community-server.x86_64                                 8.0.24-1.el7                                  mysql
mysql-community-server.x86_64                                 8.0.25-1.el7                                  mysql
mysql-community-server.x86_64                                 8.0.26-1.el7                                  mysql
mysql-community-server.x86_64                                 8.0.27-1.el7                                  mysql
mysql-community-server.x86_64                                 8.0.28-1.el7                                  mysql
mysql-community-server.x86_64                                 8.0.30-1.el7                                  mysql
mysql-community-server.x86_64                                 8.0.31-1.el7                                  mysql
mysql-community-server.x86_64                                 8.0.32-1.el7                                  mysql
mysql-community-server.x86_64                                 8.0.33-1.el7                                  mysql
mysql-community-server.x86_64                                 8.0.34-1.el7                                  mysql
mysql-community-server.x86_64                                 8.0.35-1.el7                                  mysql
mysql-community-server.x86_64                                 8.0.36-1.el7                                  mysql
mysql-community-server.x86_64                                 8.0.37-1.el7                                  mysql
mysql-community-server.x86_64                                 8.0.39-1.el7                                  mysql
mysql-community-server.x86_64                                 8.0.40-1.el7                                  mysql
mysql-community-server.x86_64                                 8.0.41-1.el7                                  mysql
mysql-community-server.x86_64                                 8.0.42-1.el7                                  mysql

[root@centos7 ~]# yum -y install mysql-community-server

[root@centos7 ~]# systemctl enable --now mysqld

[root@centos7 ~]# mysql -V
mysql  Ver 8.0.42 for Linux on x86_64 (MySQL Community Server - GPL)

[root@centos7 ~]# systemctl status mysqld
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Tue 2025-05-27 03:23:18 CST; 25s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 1153 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 1219 (mysqld)
   Status: "Server is operational"
   CGroup: /system.slice/mysqld.service
           └─1219 /usr/sbin/mysqld

May 27 03:23:14 centos7 systemd[1]: Starting MySQL Server...
May 27 03:23:18 centos7 systemd[1]: Started MySQL Server.

# 获取mysql 5.7初始密码
[root@centos7 ~]# grep password /var/log/mysqld.log
2025-05-26T19:23:15.760607Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: ws6_srh4rk=M
# "ws6_srh4rk=M"就是MySQL的初始密码

# 修改mysql密码
[root@centos7 ~]# mysqladmin -uroot -p'ws6_srh4rk=M' password 123456
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
mysqladmin: unable to change password; error: 'Your password does not satisfy the current policy requirements'

[root@centos7 ~]# mysqladmin -uroot -p'ws6_srh4rk=M' password Raymond@2025
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.

[root@centos7 ~]#  mysql -uroot -p'Raymond@2025'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 13
Server version: 8.0.42 MySQL Community Server - GPL

Copyright (c) 2000, 2025, 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'forhelp. Type '\c' to clear the current input statement.

mysql> status
--------------
mysql  Ver 8.0.42 for Linux on x86_64 (MySQL Community Server - GPL)

Connection id:		13
Current database:	
Current user:		root@localhost
SSL:			Not in use
Current pager:		stdout
Using outfile:		''
Using delimiter:	;
Server version:		8.0.42 MySQL Community Server - GPL
Protocol version:	10
Connection:		Localhost via UNIX socket
Server characterset:	utf8mb4
Db     characterset:	utf8mb4
Client characterset:	utf8mb4
Conn.  characterset:	utf8mb4
UNIX socket:		/var/lib/mysql/mysql.sock
Binary data as:		Hexadecimal
Uptime:			4 min 2 sec

Threads: 2  Questions: 11  Slow queries: 0  Opens: 140  Flush tables: 3  Open tables: 56  Queries per second avg: 0.045
--------------

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows inset (0.00 sec)

mysql> exit
Bye

复制

2.2.1.2 MySQL 8.4

在Rocky 10和Almalinux 10上安装MySQL:

代码语言:javascript
代码运行次数:0
运行
复制
[root@rocky10 ~]# yum list mysql*-server --showduplicates
Last metadata expiration check: 0:00:29 ago on Tue 10 Jun 2025 11:20:22 AM CST.
Available Packages
mysql8.4-server.x86_64                                   8.4.4-2.el10                                   appstream

[root@rocky10 ~]# yum install -y mysql8.4-server

[root@rocky10 ~]# systemctl enable --now mysqld

[root@rocky10 ~]# ls /var/lib/mysql
 auto.cnf          client-key.pem      '#innodb_redo'     mysql_upgrade_history   public_key.pem
 binlog.000001    '#ib_16384_0.dblwr''#innodb_temp'     mysql_upgrade_info      server-cert.pem
 binlog.index     '#ib_16384_1.dblwr'   mysql             mysqlx.sock             server-key.pem
 ca-key.pem        ib_buffer_pool       mysql.ibd         mysqlx.sock.lock        sys
 ca.pem            ibdata1              mysql.sock        performance_schema      undo_001
 client-cert.pem   ibtmp1               mysql.sock.lock   private_key.pem         undo_002

[root@rocky10 ~]# mysql -V
mysql  Ver 8.4.4 for Linux on x86_64 (Source distribution)

[root@rocky10 ~]# systemctl status mysqld
● mysqld.service - MySQL 8.4 database server
     Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; preset: disabled)
     Active: active (running) since Tue 2025-06-10 11:22:48 CST; 32s ago
 Invocation: 9156f6bbf370431887df1a3d38689b85
    Process: 1529 ExecStartPre=/usr/libexec/mysql-check-socket (code=exited, status=0/SUCCESS)
    Process: 1555 ExecStartPre=/usr/libexec/mysql-prepare-db-dir mysqld.service (code=exited, status=0/SUCCESS)
   Main PID: 1628 (mysqld)
     Status: "Server is operational"
      Tasks: 35 (limit: 10497)
     Memory: 440.3M (peak: 454.9M)
        CPU: 2.949s
     CGroup: /system.slice/mysqld.service
             └─1628 /usr/libexec/mysqld --basedir=/usr

Jun 10 11:22:44 rocky10 systemd[1]: Starting mysqld.service - MySQL 8.4 database server...
Jun 10 11:22:44 rocky10 mysql-prepare-db-dir[1555]: Initializing MySQL database
Jun 10 11:22:48 rocky10 systemd[1]: Started mysqld.service - MySQL 8.4 database server.

[root@rocky10 ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.4.4 Source distribution

Copyright (c) 2000, 2025, 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'forhelp. Type '\c' to clear the current input statement.

mysql> status
--------------
mysql  Ver 8.4.4 for Linux on x86_64 (Source distribution)

Connection id:		8
Current database:	
Current user:		root@localhost
SSL:			Not in use
Current pager:		stdout
Using outfile:		''
Using delimiter:	;
Server version:		8.4.4 Source distribution
Protocol version:	10
Connection:		Localhost via UNIX socket
Server characterset:	utf8mb4
Db     characterset:	utf8mb4
Client characterset:	utf8mb4
Conn.  characterset:	utf8mb4
UNIX socket:		/var/lib/mysql/mysql.sock
Binary data as:		Hexadecimal
Uptime:			58 sec

Threads: 2  Questions: 6  Slow queries: 0  Opens: 120  Flush tables: 3  Open tables: 36  Queries per second avg: 0.103
--------------

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows inset (0.01 sec)

mysql> exit
Bye

复制

在CentOS Stream 10上安装MySQL:

代码语言:javascript
代码运行次数:0
运行
复制
[root@centos10 ~]# yum list mysql-server --showduplicates
Last metadata expiration check: 0:02:19 ago on Fri 18 Apr 2025 08:47:00 PM CST.
Available Packages
mysql-server.x86_64                                      8.4.2-1.el10                                       appstream
mysql-server.x86_64                                      8.4.2-4.el10                                       appstream
mysql-server.x86_64                                      8.4.2-5.el10                                       appstream

[root@centos10 ~]# yum install -y mysql-server

[root@centos10 ~]# systemctl enable --now mysqld

[root@centos10 ~]# ls /var/lib/mysql
 auto.cnf        client-cert.pem      ibdata1         mysql.ibd               mysqlx.sock          server-cert.pem
 binlog.000001   client-key.pem       ibtmp1          mysql.sock              mysqlx.sock.lock     server-key.pem
 binlog.index   '#ib_16384_0.dblwr''#innodb_redo'   mysql.sock.lock         performance_schema   sys
 ca-key.pem     '#ib_16384_1.dblwr''#innodb_temp'   mysql_upgrade_history   private_key.pem      undo_001
 ca.pem          ib_buffer_pool       mysql           mysql_upgrade_info      public_key.pem       undo_002

[root@centos10 ~]# mysql -V
mysql  Ver 8.4.2 for Linux on x86_64 (Source distribution)

[root@centos10 ~]# systemctl status mysqld
● mysqld.service - MySQL 8.4 database server
     Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; preset: disabled)
     Active: active (running) since Fri 2025-04-18 20:52:36 CST; 1min 29s ago
 Invocation: 88e292c61b504209b59f1c6c66e8a394
    Process: 1460 ExecStartPre=/usr/libexec/mysql-check-socket (code=exited, status=0/SUCCESS)
    Process: 1483 ExecStartPre=/usr/libexec/mysql-prepare-db-dir mysqld.service (code=exited, status=0/SUCCESS)
   Main PID: 1556 (mysqld)
     Status: "Server is operational"
      Tasks: 34 (limit: 10497)
     Memory: 446.1M (peak: 454M)
        CPU: 3.678s
     CGroup: /system.slice/mysqld.service
             └─1556 /usr/libexec/mysqld --basedir=/usr

Apr 18 20:52:31 centos10 systemd[1]: Starting mysqld.service - MySQL 8.4 database server...
Apr 18 20:52:32 centos10 mysql-prepare-db-dir[1483]: Initializing MySQL database
Apr 18 20:52:36 centos10 systemd[1]: Started mysqld.service - MySQL 8.4 database server.

[root@centos10 ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.4.2 Source distribution

Copyright (c) 2000, 2024, 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'forhelp. Type '\c' to clear the current input statement.

mysql> status
--------------
mysql  Ver 8.4.2 for Linux on x86_64 (Source distribution)

Connection id:		8
Current database:	
Current user:		root@localhost
SSL:			Not in use
Current pager:		stdout
Using outfile:		''
Using delimiter:	;
Server version:		8.4.2 Source distribution
Protocol version:	10
Connection:		Localhost via UNIX socket
Server characterset:	utf8mb4
Db     characterset:	utf8mb4
Client characterset:	utf8mb4
Conn.  characterset:	utf8mb4
UNIX socket:		/var/lib/mysql/mysql.sock
Binary data as:		Hexadecimal
Uptime:			1 min 54 sec

Threads: 2  Questions: 6  Slow queries: 0  Opens: 120  Flush tables: 3  Open tables: 36  Queries per second avg: 0.052
--------------

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows inset (0.00 sec)

mysql> exit
Bye

复制

在Rocky 8/9、Almalinux 8/9、CentOS Stream 8/9、openEuler 22.03/24.03 LTS、AnolisOS 8/23、OpenCloudOS 8/9、Kylin Server v10、UOS Server v20上安装MySQL:

打开“https://dev.mysql.com/downloads”网址,选择“MySQL Yum Repository(MySQL Yum资源库)”,如图2所示。

t2

图2 下载Yum仓库包

然后根据系统版本下载相应的安装包,如图3所示。

t3

图3 下载Yum仓库包

Rocky 9、Almalinux 9、CentOS Stream 9、AnolisOS 23、OpenCloudOS 9:

代码语言:javascript
代码运行次数:0
运行
复制
# Rocky、Almalinux、CentOS、openEuler、AnolisOS、OpenCloudOS、Kylin Server、Uos Server默认没有wget包,需要安装
yum install -y wget

[root@rocky9 ~]# wget https://dev.mysql.com/get/mysql84-community-release-el9-1.noarch.rpm

[root@rocky9 ~]# rpm -ivh mysql84-community-release-el9-1.noarch.rpm

[root@rocky9 ~]# yum makecache

[root@rocky9 ~]# yum list mysql-community-server --showduplicates
Last metadata expiration check: 0:00:06 ago on Fri 18 Apr 2025 07:37:00 PM CST.
Available Packages
mysql-community-server.x86_64                           8.4.0-1.el9                           mysql-8.4-lts-community
mysql-community-server.x86_64                           8.4.2-1.el9                           mysql-8.4-lts-community
mysql-community-server.x86_64                           8.4.3-1.el9                           mysql-8.4-lts-community
mysql-community-server.x86_64                           8.4.4-1.el9                           mysql-8.4-lts-community
mysql-community-server.x86_64                           8.4.5-1.el9                           mysql-8.4-lts-community

[root@rocky9 ~]# yum install -y mysql-community-server

[root@rocky9 ~]# systemctl enable --now mysqld

[root@rocky9 ~]# ls /var/lib/mysql
 auto.cnf        client-cert.pem      ibdata1         mysql.ibd               private_key.pem   undo_001
 binlog.000001   client-key.pem       ibtmp1          mysql.sock              public_key.pem    undo_002
 binlog.index   '#ib_16384_0.dblwr''#innodb_redo'   mysql.sock.lock         server-cert.pem
 ca-key.pem     '#ib_16384_1.dblwr''#innodb_temp'   mysql_upgrade_history   server-key.pem
 ca.pem          ib_buffer_pool       mysql           performance_schema      sys

[root@rocky9 ~]# mysql -V
mysql  Ver 8.4.5 for Linux on x86_64 (MySQL Community Server - GPL

[root@rocky9 ~]# systemctl status mysqld
● mysqld.service - MySQL Server
     Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; preset: disabled)
     Active: active (running) since Sat 2025-04-12 21:14:16 CST; 49s ago
       Docs: man:mysqld(8)
             http://dev.mysql.com/doc/refman/en/using-systemd.html
    Process: 12094 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
   Main PID: 12159 (mysqld)
     Status: "Server is operational"
      Tasks: 35 (limit: 10892)
     Memory: 443.0M
        CPU: 3.806s
     CGroup: /system.slice/mysqld.service
             └─12159 /usr/sbin/mysqld

Apr 12 21:14:11 rocky9 systemd[1]: Starting MySQL Server...
Apr 12 21:14:16 rocky9 systemd[1]: Started MySQL Server.

# 获取MySQL初始密码
[root@rocky9 ~]# grep password /var/log/mysqld.log
2025-04-12T13:52:56.917890Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: jqdeiDdgi3_I
# "jqdeiDdgi3_I"就是MySQL的初始密码

# 修改mysql密码
[root@rocky9 ~]# mysqladmin -uroot -p'jqdeiDdgi3_I' password 123456
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
mysqladmin: unable to change password; error: 'Your password does not satisfy the current policy requirements'
# 上面报错提示密码太简单

[root@rocky9 ~]# mysqladmin -uroot -p'jqdeiDdgi3_I' password Raymond@2025
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.

[root@rocky9 ~]# mysql -uroot -p'Raymond@2025'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.4.5 MySQL Community Server - GPL

Copyright (c) 2000, 2025, 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'forhelp. Type '\c' to clear the current input statement.

mysql> status
--------------
mysql  Ver 8.4.5 for Linux on x86_64 (MySQL Community Server - GPL)

Connection id:		9
Current database:	
Current user:		root@localhost
SSL:			Not in use
Current pager:		stdout
Using outfile:		''
Using delimiter:	;
Server version:		8.4.5 MySQL Community Server - GPL
Protocol version:	10
Connection:		Localhost via UNIX socket
Server characterset:	utf8mb4
Db     characterset:	utf8mb4
Client characterset:	utf8mb4
Conn.  characterset:	utf8mb4
UNIX socket:		/var/lib/mysql/mysql.sock
Binary data as:		Hexadecimal
Uptime:			59 sec

Threads: 2  Questions: 9  Slow queries: 0  Opens: 130  Flush tables: 3  Open tables: 46  Queries per second avg: 0.152
--------------

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows inset (0.01 sec)

mysql> exit
Bye

复制

Rocky 8、Almalinux 8、CentOS Stream 8、AnolisOS 8、OpenCloudOS 8:

代码语言:javascript
代码运行次数:0
运行
复制
[root@rocky8 ~]# yum install -y wget

[root@rocky8 ~]# wget https://dev.mysql.com/get/mysql84-community-release-el8-1.noarch.rpm

[root@rocky8 ~]# rpm -ivh mysql84-community-release-el8-1.noarch.rpm

[root@rocky8 ~]# yum makecache

[root@rocky8 ~]# yum list mysql-community-server --showduplicates
Last metadata expiration check: 0:01:43 ago on Sat 12 Apr 2025 11:29:44 PM CST.
Error: No matching Packages to list
# 找不到安装包

复制

在“Rocky 8、Almalinux 8、CentOS Stream 8、AnolisOS 8、OpenCloudOS 8”操作系统上添加镜像仓库后,找不到安装包,需要从官方网站下载安装包来安装。

打开"https://dev.mysql.com/downloads/mysql"网址,"Select Version(选择版本)"为:8.4.4 LTS,“Select Operating System(选择操作系统)”为:Red Hat Enterprise Linux / Oracle Linux,"Select OS Version(选择操作系统版本)"为:Red Hat Enterprise Linux 8 / Oracle Linux 8 (x86 , 64-bit),然后选择”RPM Bundel“后面的”Download“,如图4所示。

t4

图4 下载RPM包

代码语言:javascript
代码运行次数:0
运行
复制
[root@rocky8 ~]# wget https://dev.mysql.com/get/Downloads/MySQL-8.4/mysql-8.4.5-1.el8.x86_64.rpm-bundle.tar

[root@rocky8 ~]# tar xf tar xf mysql-8.4.5-1.el8.x86_64.rpm-bundle.tar 

[root@rocky8 ~]# yum install -y perl libaio

[root@rocky8 ~]# rpm -ivh mysql-community-client-plugins-8.4.5-1.el8.x86_64.rpm

[root@rocky8 ~]# rpm -ivh mysql-community-common-8.4.5-1.el8.x86_64.rpm

[root@rocky8 ~]# rpm -ivh mysql-community-libs-8.4.5-1.el8.x86_64.rpm

[root@rocky8 ~]# rpm -ivh mysql-community-client-8.4.5-1.el8.x86_64.rpm

[root@rocky8 ~]# rpm -ivh mysql-community-icu-data-files-8.4.5-1.el8.x86_64.rpm

[root@rocky8 ~]# yum install -y net-tools

[root@rocky8 ~]# rpm -ivh mysql-community-server-8.4.5-1.el8.x86_64.rpm

[root@rocky8 ~]# systemctl enable --now mysqld

[root@rocky8 ~]# ls /var/lib/mysql
 auto.cnf        client-cert.pem      ibdata1         mysql.ibd               private_key.pem   undo_001
 binlog.000001   client-key.pem       ibtmp1          mysql.sock              public_key.pem    undo_002
 binlog.index   '#ib_16384_0.dblwr''#innodb_redo'   mysql.sock.lock         server-cert.pem
 ca-key.pem     '#ib_16384_1.dblwr''#innodb_temp'   mysql_upgrade_history   server-key.pem
 ca.pem          ib_buffer_pool       mysql           performance_schema      sys

[root@rocky8 ~]# mysql -V
mysql  Ver 8.4.5 for Linux on x86_64 (MySQL Community Server - GPL)

[root@rocky8 ~]# systemctl status mysqld
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Sat 2025-04-19 01:13:21 CST; 35s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 15045 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 15112 (mysqld)
   Status: "Server is operational"
    Tasks: 35 (limit: 12176)
   Memory: 469.9M
   CGroup: /system.slice/mysqld.service
           └─15112 /usr/sbin/mysqld

Apr 19 01:13:17 anolis8 systemd[1]: Starting MySQL Server...
Apr 19 01:13:21 anolis8 systemd[1]: Started MySQL Server.

# 获取MySQL初始密码
[root@rocky8 ~]# grep password /var/log/mysqld.log
2025-04-18T17:13:19.074870Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: gOtp+U:/L11&
# "y7:Fc>lcCpl!"就是MySQL的初始密码

# 修改mysql密码
[root@rocky8 ~]# mysqladmin -uroot -p'gOtp+U:/L11&' password 123456
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
mysqladmin: unable to change password; error: 'Your password does not satisfy the current policy requirements'
# 上面报错提示密码太简单

[root@rocky8 ~]# mysqladmin -uroot -p'gOtp+U:/L11&' password Raymond@2025
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.

[root@rocky8 ~]# mysql -uroot -p'Raymond@2025'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.4.5 MySQL Community Server - GPL

Copyright (c) 2000, 2025, 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'forhelp. Type '\c' to clear the current input statement.

mysql> status
--------------
mysql  Ver 8.4.5 for Linux on x86_64 (MySQL Community Server - GPL)

Connection id:		9
Current database:	
Current user:		root@localhost
SSL:			Not in use
Current pager:		stdout
Using outfile:		''
Using delimiter:	;
Server version:		8.4.5 MySQL Community Server - GPL
Protocol version:	10
Connection:		Localhost via UNIX socket
Server characterset:	utf8mb4
Db     characterset:	utf8mb4
Client characterset:	utf8mb4
Conn.  characterset:	utf8mb4
UNIX socket:		/var/lib/mysql/mysql.sock
Binary data as:		Hexadecimal
Uptime:			1 min 48 sec

Threads: 2  Questions: 9  Slow queries: 0  Opens: 130  Flush tables: 3  Open tables: 46  Queries per second avg: 0.083
--------------

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows inset (0.00 sec)

mysql> exit
Bye

复制

openEuler 22.03/24.03 LTS、Kylin Server v10、UOS Server v20:

代码语言:javascript
代码运行次数:0
运行
复制
[root@openeuler2403 ~]#  yum install -y wget

[root@openeuler2403 ~]#  wget https://dev.mysql.com/get/mysql84-community-release-el8-1.noarch.rpm

[root@openeuler2403 ~]#  rpm -ivh mysql84-community-release-el8-1.noarch.rpm

[root@openeuler2403 ~]#  yum makecache

[root@openeuler2403 ~]#  yum list mysql-community-server --showduplicates
Last metadata expiration check: 0:00:19 ago on Fri 18 Apr 2025 03:09:05 PM CST.
Available Packages
mysql-community-server.x86_64                           8.4.0-1.el8                           mysql-8.4-lts-community
mysql-community-server.x86_64                           8.4.2-1.el8                           mysql-8.4-lts-community
mysql-community-server.x86_64                           8.4.3-1.el8                           mysql-8.4-lts-community
mysql-community-server.x86_64                           8.4.4-1.el8                           mysql-8.4-lts-community
mysql-community-server.x86_64                           8.4.5-1.el8                           mysql-8.4-lts-communit

[root@openeuler2403 ~]# yum install -y mysql-community-server

[root@openeuler2403 ~]# systemctl enable --now mysqld

[root@openeuler2403 ~]# ls /var/lib/mysql
 auto.cnf        client-cert.pem      ibdata1         mysql.ibd               private_key.pem   undo_001
 binlog.000001   client-key.pem       ibtmp1          mysql.sock              public_key.pem    undo_002
 binlog.index   '#ib_16384_0.dblwr''#innodb_redo'   mysql.sock.lock         server-cert.pem
 ca-key.pem     '#ib_16384_1.dblwr''#innodb_temp'   mysql_upgrade_history   server-key.pem
 ca.pem          ib_buffer_pool       mysql           performance_schema      sys

[root@openeuler2403 ~]# mysql -V
mysql  Ver 8.4.5 for Linux on x86_64 (MySQL Community Server - GPL)

[root@openeuler2403 ~]# systemctl status mysqld
● mysqld.service - MySQL Server
     Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; preset: disabled)
     Active: active (running) since Fri 2025-04-18 15:25:52 CST; 38s ago
       Docs: man:mysqld(8)
             http://dev.mysql.com/doc/refman/en/using-systemd.html
    Process: 1793 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
   Main PID: 1859 (mysqld)
     Status: "Server is operational"
      Tasks: 35 (limit: 8901)
     Memory: 467.2M ()
     CGroup: /system.slice/mysqld.service
             └─1859 /usr/sbin/mysqld

Apr 18 15:25:48 openeuler2403 systemd[1]: Starting MySQL Server...
Apr 18 15:25:51 openeuler2403 (mysqld)[1859]: mysqld.service: Referenced but unset environment variable evaluates to>
Apr 18 15:25:52 openeuler2403 systemd[1]: Started MySQL Server.

# 获取MySQL初始密码
[root@openeuler2403 ~]# grep password /var/log/mysqld.log
2025-04-18T07:25:49.630875Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: beM?N(3yyz&y
# "jqdeiDdgi3_I"就是MySQL的初始密码

# 修改mysql密码
[root@openeuler2403 ~]# mysqladmin -uroot -p'beM?N(3yyz&y' password 123456
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
mysqladmin: unable to change password; error: 'Your password does not satisfy the current policy requirements'
# 上面报错提示密码太简单

[root@openeuler2403 ~]# mysqladmin -uroot -p'beM?N(3yyz&y' password Raymond@2025
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.

[root@openeuler2403 ~]# mysql -uroot -p'Raymond@2025'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.4.5 MySQL Community Server - GPL

Copyright (c) 2000, 2025, 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'forhelp. Type '\c' to clear the current input statement.

mysql> status
--------------
mysql  Ver 8.4.5 for Linux on x86_64 (MySQL Community Server - GPL)

Connection id:		10
Current database:	
Current user:		root@localhost
SSL:			Not in use
Current pager:		stdout
Using outfile:		''
Using delimiter:	;
Server version:		8.4.5 MySQL Community Server - GPL
Protocol version:	10
Connection:		Localhost via UNIX socket
Server characterset:	utf8mb4
Db     characterset:	utf8mb4
Client characterset:	utf8mb4
Conn.  characterset:	utf8mb4
UNIX socket:		/var/lib/mysql/mysql.sock
Binary data as:		Hexadecimal
Uptime:			2 min 18 sec

Threads: 2  Questions: 12  Slow queries: 0  Opens: 140  Flush tables: 3  Open tables: 56  Queries per second avg: 0.086
--------------

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows inset (0.01 sec)

mysql> exit
Bye

复制

在CentOS 7上安装MySQL:

代码语言:javascript
代码运行次数:0
运行
复制
[root@centos7 ~]# yum install -y wget

[root@centos7 ~]# wget https://dev.mysql.com/get/mysql84-community-release-el7-1.noarch.rpm

[root@centos7 ~]# rpm -ivh mysql84-community-release-el7-1.noarch.rpm

[root@centos7 ~]# yum makecache

[root@centos7 ~]# yum list mysql-community-server --showduplicates
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Available Packages
mysql-community-server.x86_64                           8.4.0-1.el7                           mysql-8.4-lts-community
mysql-community-server.x86_64                           8.4.2-1.el7                           mysql-8.4-lts-community
mysql-community-server.x86_64                           8.4.3-1.el7                           mysql-8.4-lts-community
mysql-community-server.x86_64                           8.4.4-1.el7                           mysql-8.4-lts-community
mysql-community-server.x86_64                           8.4.5-1.el7                           mysql-8.4-lts-communit

[root@centos7 ~]# yum install -y mysql-community-server

[root@centos7 ~]# systemctl enable --now mysqld

[root@centos7 ~]# mysql -V
mysql  Ver 8.4.5 for Linux on x86_64 (MySQL Community Server - GPL)

[root@centos7 ~]# systemctl status mysqld
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Sat 2025-04-19 04:07:32 CST; 38s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 1185 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 1249 (mysqld)
   Status: "Server is operational"
   CGroup: /system.slice/mysqld.service
           └─1249 /usr/sbin/mysqld

Apr 19 04:07:27 centos7 systemd[1]: Starting MySQL Server...
Apr 19 04:07:32 centos7 systemd[1]: Started MySQL Server.

# 获取mysql初始密码
[root@centos7 ~]# grep password /var/log/mysqld.log
2025-04-18T20:07:29.114303Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: )puUpc=M8VJk
# “)puUpc=M8VJk”就是mysql的初始密码

# 修改mysql密码
[root@centos7 ~]# mysqladmin -uroot -p')puUpc=M8VJk' password 123456
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
mysqladmin: unable to change password; error: 'Your password does not satisfy the current policy requirements'
# 上面报错提示密码太简单

[root@centos7 ~]# mysqladmin -uroot -p')puUpc=M8VJk' password Raymond@2025
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.

[root@centos7 ~]# mysql -uroot -p'Raymond@2025'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.4.5 MySQL Community Server - GPL

Copyright (c) 2000, 2025, 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'forhelp. Type '\c' to clear the current input statement.

mysql> status
--------------
mysql  Ver 8.4.5 for Linux on x86_64 (MySQL Community Server - GPL)

Connection id:		10
Current database:	
Current user:		root@localhost
SSL:			Not in use
Current pager:		stdout
Using outfile:		''
Using delimiter:	;
Server version:		8.4.5 MySQL Community Server - GPL
Protocol version:	10
Connection:		Localhost via UNIX socket
Server characterset:	utf8mb4
Db     characterset:	utf8mb4
Client characterset:	utf8mb4
Conn.  characterset:	utf8mb4
UNIX socket:		/var/lib/mysql/mysql.sock
Binary data as:		Hexadecimal
Uptime:			2 min 11 sec

Threads: 2  Questions: 12  Slow queries: 0  Opens: 140  Flush tables: 3  Open tables: 56  Queries per second avg: 0.091
--------------

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows inset (0.00 sec)

mysql> exit
Bye

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 2.2 包安装
    • 2.2.1 Yum资源库安装MySQL
      • 2.2.1.1 MySQL 8.0
      • 2.2.1.2 MySQL 8.4
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档