通过 Yum Repository 安装 MySQL

RPM 包和二进制包安装方式虽然简单,但也有一些缺陷,比如需要下载的包比较多,且包之间安装有先后依赖关系,最重要的是升级不方便。如果有新版本,则需要从新下载所有包进行替换。

为了解决这些不便之处,MySQL 官方提供了一种全新的安装方式--Yum Repository。Yum(全称为Yellow dog Updater,Modified)是一个在 Fedora 和 RedHat 以及 CentOS 中的 Shell 前段软件包管理器。基于 RPM 包管理, 能够从制定的服务器自动下载 RPM 包并且安装,可以自动处理依赖性关系,并且一次安装所有依赖的软件包,无须繁琐地一次次下载和安装。

Yum Repository 的安装包非常小,8.0 版本只有 25KB, 下载方式和其他 RPM 包类似,这里不再累述。下面详细介绍 Yum Repository 的安装和使用方法。

1、下载安装 Yum Repository

wget https://repo.mysql.com//mysql80-community-release-el7-3.noarch.rpm

[root@mgr04 ~]# rpm -ivh mysql80-community-release-el7-3.noarch.rpm 
warning: mysql80-community-release-el7-3.noarch.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql80-community-release-el7-3  ################################# [100%]

安装完毕后,在 /etc/yum.repos.d/ 下多了 mysql-community.repo 和 mysql-community-source.repo 这两个文件,它们分别是 MySQL 社区版 RPM 包和源码包的 Yum 源文件,里面记录了支持的软件版本和下载相关的一些参数。

2、使用 Yum Repository 来安装MySQL 8.0

用 cat 命令截取 mysql-community.repo 的部分内容,如下所示:

# Enable to use MySQL 5.7
[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql80-community]
name=MySQL 8.0 Community Server
baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

可以看出,最新 GA 版本 8.0 的 enabled=1,其它版本均为 0。如果安装最新 GA 版本的 MySQL,则不用做任何设置, 直接执行如下命令:

[root@mgr04 ~]# yum install mysql-community-server
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
base                                                                                                          | 3.6 kB  00:00:00     
epel                                                                                                          | 4.7 kB  00:00:00     
extras                                                                                                        | 2.9 kB  00:00:00     
mysql-connectors-community                                                                                    | 2.6 kB  00:00:00     
mysql-tools-community                                                                                         | 2.6 kB  00:00:00     
mysql80-community                                                                                             | 2.6 kB  00:00:00     
updates                                                                                                       | 2.9 kB  00:00:00     
(1/5): mysql-connectors-community/x86_64/primary_db                                                           |  80 kB  00:00:05     
(2/5): mysql-tools-community/x86_64/primary_db                                                                |  88 kB  00:00:05     
(3/5): mysql80-community/x86_64/primary_db                                                                    | 165 kB  00:00:05     
(4/5): epel/x86_64/updateinfo                                                                                 | 1.0 MB  00:00:06     
(5/5): epel/x86_64/primary_db                                                                                 | 6.9 MB  00:00:08     
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-server.x86_64 0:8.0.25-1.el7 will be installed
--> Processing Dependency: mysql-community-common(x86-64) = 8.0.25-1.el7 for package: mysql-community-server-8.0.25-1.el7.x86_64
--> Processing Dependency: mysql-community-client(x86-64) >= 8.0.11 for package: mysql-community-server-8.0.25-1.el7.x86_64
--> Running transaction check
---> Package mysql-community-client.x86_64 0:8.0.25-1.el7 will be installed
--> Processing Dependency: mysql-community-client-plugins = 8.0.25-1.el7 for package: mysql-community-client-8.0.25-1.el7.x86_64
--> Processing Dependency: mysql-community-libs(x86-64) >= 8.0.11 for package: mysql-community-client-8.0.25-1.el7.x86_64
---> Package mysql-community-common.x86_64 0:8.0.25-1.el7 will be installed
--> Running transaction check
---> Package mysql-community-client-plugins.x86_64 0:8.0.25-1.el7 will be installed
---> Package mysql-community-libs.x86_64 0:8.0.25-1.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=====================================================================================================================================
 Package                                      Arch                 Version                     Repository                       Size
=====================================================================================================================================
Installing:
 mysql-community-server                       x86_64               8.0.25-1.el7                mysql80-community               428 M
Installing for dependencies:
 mysql-community-client                       x86_64               8.0.25-1.el7                mysql80-community                46 M
 mysql-community-client-plugins               x86_64               8.0.25-1.el7                mysql80-community               189 k
 mysql-community-common                       x86_64               8.0.25-1.el7                mysql80-community               614 k
 mysql-community-libs                         x86_64               8.0.25-1.el7                mysql80-community               4.0 M

Transaction Summary
=====================================================================================================================================
Install  1 Package (+4 Dependent packages)

Total download size: 478 M
Installed size: 2.2 G
Is this ok [y/d/N]: y

从安装过程可以看出,一些包被废弃,一些被更新,包之间的依赖被自动处理,整个过程几乎不需要人工介入,非常方便。

如有其它低版本的 MySQL 安装需求,比如 5.7 版本,那么可以将源文件中[mysql80-community]下的配置项 enabled 改为 0,同时将[mysql57-community] 下对应参数改为 1。或者使用如下命令更改更方便:

yum-config-manager --disable mysql80-community

yum-config-manager --enable mysql57-community

3、启动 MySQL

[root@mgr04 ~]# systemctl start mysqld.service 

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

May 19 22:56:28 mgr04 systemd[1]: Starting MySQL Server...
May 19 22:56:38 mgr04 systemd[1]: Started MySQL Server.

因为有悔,所以披星戴月;因为有梦,所以奋不顾身! 个人博客首发:easydb.net 微信公众号:easydb 关注我,不走丢!

posted @ 2021-05-19 23:56  easydba  阅读(222)  评论(0编辑  收藏  举报