在CentOS 7上安装mySQL 5.7发现需要三条命令,而不是像以往安装其他软件一样一条yum就搞定,这是为什么呢?

首先我们来看看这三条命令是什么

wget http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
yum -y install mysql57-community-release-el7-10.noarch.rpm
yum -y install mysql-community-server

这三条命令都在做什么呢?
首先第一条命令,通过wget我们知道是在下载一个rpm的包到本地,这个包就是mySQL的安装包了么?如果是的话,那么后面只需要一条命令就可以安装mysql了,而不是需要两条。

其实是yum的repo里面并没有mySQL的安装源,而对于下载的rpm包的安装,是将两条新的安装源加入到yum repositories。

再运行yum -y install mysql-community-server才是真正的安装mySQL

验证
我们登录到CentOS7的机器,列出当前的yum repo

[root@iZm5e67mdyatjusk69dodoZ ~]# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
repo id                                         repo name                                                              status
base/7/x86_64                                   CentOS-7                                                               10,070
docker-ce-stable/x86_64                         Docker CE Stable - x86_64                                                  79
epel/x86_64                                     Extra Packages for Enterprise Linux 7 - x86_64                         13,416
extras/7/x86_64                                 CentOS-7                                                                  412
updates/7/x86_64                                CentOS-7                                                                  900
repolist: 24,877

好像没有mysql相关的,顺便查一下来确认一下

[root@iZm5e67mdyatjusk69dodoZ ~]# yum search mysql-community-server
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Warning: No matches found for: mysql-community-server
No matches found

OK,确实查不到。那咱们来安装一下通过wget下载的rpm

[root@iZm5e67mdyatjusk69dodoZ ~]# yum -y install mysql57-community-release-el7-10.noarch.rpm 
Loaded plugins: fastestmirror
Examining mysql57-community-release-el7-10.noarch.rpm: mysql57-community-release-el7-10.noarch
Marking mysql57-community-release-el7-10.noarch.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package mysql57-community-release.noarch 0:el7-10 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================================================================
 Package                            Arch            Version          Repository                                         Size
=============================================================================================================================
Installing:
 mysql57-community-release          noarch          el7-10           /mysql57-community-release-el7-10.noarch           30 k

Transaction Summary
=============================================================================================================================
Install  1 Package

Total size: 30 k
Installed size: 30 k
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : mysql57-community-release-el7-10.noarch                                                                   1/1 
  Verifying  : mysql57-community-release-el7-10.noarch                                                                   1/1 

Installed:
  mysql57-community-release.noarch 0:el7-10                                                                                  

Complete!

现在这个rpm已经装好了,咱们再来看一下yum的repo变成什么样子了

[root@iZm5e67mdyatjusk69dodoZ ~]# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
mysql-connectors-community                                                                            | 2.5 kB  00:00:00     
mysql-tools-community                                                                                 | 2.5 kB  00:00:00     
mysql57-community                                                                                     | 2.5 kB  00:00:00     
(1/3): mysql-tools-community/x86_64/primary_db                                                        |  76 kB  00:00:00     
(2/3): mysql57-community/x86_64/primary_db                                                            | 224 kB  00:00:00     
(3/3): mysql-connectors-community/x86_64/primary_db                                                   |  62 kB  00:00:00     
repo id                                              repo name                                                         status
base/7/x86_64                                        CentOS-7                                                          10,070
docker-ce-stable/x86_64                              Docker CE Stable - x86_64                                             79
epel/x86_64                                          Extra Packages for Enterprise Linux 7 - x86_64                    13,416
extras/7/x86_64                                      CentOS-7                                                             412
mysql-connectors-community/x86_64                    MySQL Connectors Community                                           165
mysql-tools-community/x86_64                         MySQL Tools Community                                                115
mysql57-community/x86_64                             MySQL 5.7 Community Server                                           444
updates/7/x86_64                                     CentOS-7                                                             900
repolist: 25,601

看起来和上面不太一样了,多了几个和mysql相关的repo,那我们试着在搜索一下mysql-community-server

[root@iZm5e67mdyatjusk69dodoZ ~]# yum search mysql-community-server
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
============================================ N/S matched: mysql-community-server ============================================
mysql-community-server.x86_64 : A very fast and reliable SQL database server

  Name and summary matches only, use "search all" for everything.

这次找到了,这就是为什么需要三条命令来安装的原因。

参考文档
https://www.digitalocean.com/community/tutorials/how-to-install-mysql-on-centos-7

文章来源于互联网,如有雷同请联系站长删除:不懂就问之为什么CentOS安装mySQL需要三条命令

发表评论