如何使用 Yum Repository 安裝指定版本的 MySQL


自從從使用 debian 系的 apt-get 轉到使用 yum 工具之后一直不是很習慣,也沒有去看過很多工具包安裝的時候到底影響到了哪些文件等。這次借這次社區版 MySQL 安裝來一並梳理一下。

首先我們前往 https://dev.mysql.com/downloads/repo/yum/ 下載對應的 yum repo 包。

這里可以看到 官方提供了4個 repo 包提供下載:

這里對應 3 個 linux 發行版。Red Hat Enterprise Linux 7 是紅帽企業版7 后面是 Oracle Linux 7。 另外下面的 Fedora 是基於以前 Red Hat 個人版衍生而來。也是一個 Linux 發行版。 由於我這里的系統是 CentOs 7 我下載了第一個 rpm 包。

拿到包之后,我們將包添加進系統的 yum repo 列表之中。

sudo rpm -Uvh mysql80-community-release-el6-n.noarch.rpm

這個我們可以查看 CentOS 的指定路徑下的文件可以看出來其安裝后的效果。

我們進入 cd /etc/yum.repos.d 可以看到已經被我們安裝上的 mysql-community.repo  mysql-community-source.repo 兩個 repo

vi mysql-community.repo 可以查看包里面的信息。

同時我們使用 

yum repolist all | grep mysql

來查看現在跟 MySQL 相關的 yum repo情況。這個時候如果使用 yum install 會默認安裝現在 repo 里面最新的 MySQL 版本(To install the latest release from the latest GA series PS:GA(General Availability)),現在最新的版本是 8.0 。但是我現在只想安裝 5.6 版本的,所以需要變化一下。來看下面的測試結果。

[root@iz2ze46vymskz5z22xevegz etc]# yum install mysql
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-client.x86_64 0:8.0.12-1.el7 will be installed
--> Processing Dependency: mysql-community-libs(x86-64) >= 8.0.0 for package: mysql-community-client-8.0.12-1.el7.x86_64
--> Running transaction check
---> Package mariadb-libs.x86_64 1:5.5.56-2.el7 will be obsoleted
--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64
---> Package mysql-community-libs.x86_64 0:8.0.12-1.el7 will be obsoleting
--> Processing Dependency: mysql-community-common(x86-64) >= 8.0.0 for package: mysql-community-libs-8.0.12-1.el7.x86_64
--> Running transaction check
---> Package mysql-community-common.x86_64 0:8.0.12-1.el7 will be installed
---> Package mysql-community-libs-compat.x86_64 0:8.0.12-1.el7 will be obsoleting
--> Finished Dependency Resolution

Dependencies Resolved

==================================================================================================================================================================================================================
 Package                                                       Arch                                     Version                                         Repository                                           Size
==================================================================================================================================================================================================================
Installing:
 mysql-community-client                                        x86_64                                   8.0.12-1.el7                                    mysql80-community                                    26 M
 mysql-community-libs                                          x86_64                                   8.0.12-1.el7                                    mysql80-community                                   2.2 M
     replacing  mariadb-libs.x86_64 1:5.5.56-2.el7
 mysql-community-libs-compat                                   x86_64                                   8.0.12-1.el7                                    mysql80-community                                   2.1 M
     replacing  mariadb-libs.x86_64 1:5.5.56-2.el7
Installing for dependencies:
 mysql-community-common                                        x86_64                                   8.0.12-1.el7                                    mysql80-community                                   541 k

Transaction Summary
==================================================================================================================================================================================================================
Install  3 Packages (+1 Dependent package)

Total download size: 30 M

可以看到 如果我 y 同意上面的信息,就會安裝 8.0 的 MySQL 社區版。

現在我們需要調整成 5.6 的版本。

如果機器上有安裝 yum-config-manager or dnf config-manager 這兩個工具的話可以使用:

for platforms that are not dnf-enabled:

shell> sudo yum-config-manager --disable mysql80-community
shell> sudo yum-config-manager --enable mysql56-community
For dnf
-enabled platforms: shell> sudo dnf config-manager --disable mysql80-community shell> sudo dnf config-manager --enable mysql56-community

來修改成自己想要的版本。如果像我這樣。。。裸機啥都沒有也有方法可以修改,我們去剛次啊提到的 /etc/yum.repos.d/ 下,找到 mysql-community.repo 編輯他。

可以看到 8.0 版本的信息是這樣的

[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

我們將 enabled=1 改成 0 

並且將我們想要使用的 5.6 改成 1即可。讓我們再使用 yum install mysql-community-server 命令安裝 社區版 MySQL 5.6 版本。(注意,上面提到的版本 enable。同一時間只能有一個版本處於 enable 狀態)

 
         

[root@iz2ze46vymskz5z22xevegz yum.repos.d]# yum install mysql-community-server
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-server.x86_64 0:5.6.41-2.el7 will be installed
--> Processing Dependency: mysql-community-common(x86-64) = 5.6.41-2.el7 for package: mysql-community-server-5.6.41-2.el7.x86_64
--> Processing Dependency: mysql-community-client(x86-64) >= 5.6.10 for package: mysql-community-server-5.6.41-2.el7.x86_64
--> Processing Dependency: perl(Data::Dumper) for package: mysql-community-server-5.6.41-2.el7.x86_64
--> Processing Dependency: perl(DBI) for package: mysql-community-server-5.6.41-2.el7.x86_64
--> Processing Dependency: libaio.so.1(LIBAIO_0.4)(64bit) for package: mysql-community-server-5.6.41-2.el7.x86_64
--> Processing Dependency: libaio.so.1(LIBAIO_0.1)(64bit) for package: mysql-community-server-5.6.41-2.el7.x86_64
--> Processing Dependency: libaio.so.1()(64bit) for package: mysql-community-server-5.6.41-2.el7.x86_64
--> Running transaction check
---> Package libaio.x86_64 0:0.3.109-13.el7 will be installed
---> Package mysql-community-client.x86_64 0:5.6.41-2.el7 will be installed
--> Processing Dependency: mysql-community-libs(x86-64) >= 5.6.10 for package: mysql-community-client-5.6.41-2.el7.x86_64
---> Package mysql-community-common.x86_64 0:5.6.41-2.el7 will be installed
---> Package perl-DBI.x86_64 0:1.627-4.el7 will be installed
--> Processing Dependency: perl(RPC::PlServer) >= 0.2001 for package: perl-DBI-1.627-4.el7.x86_64
--> Processing Dependency: perl(RPC::PlClient) >= 0.2000 for package: perl-DBI-1.627-4.el7.x86_64
---> Package perl-Data-Dumper.x86_64 0:2.145-3.el7 will be installed
--> Running transaction check
---> Package mariadb-libs.x86_64 1:5.5.56-2.el7 will be obsoleted
---> Package mysql-community-libs.x86_64 0:5.6.41-2.el7 will be obsoleting
---> Package perl-PlRPC.noarch 0:0.2020-14.el7 will be installed
--> Processing Dependency: perl(Net::Daemon) >= 0.13 for package: perl-PlRPC-0.2020-14.el7.noarch
--> Processing Dependency: perl(Net::Daemon::Test) for package: perl-PlRPC-0.2020-14.el7.noarch
--> Processing Dependency: perl(Net::Daemon::Log) for package: perl-PlRPC-0.2020-14.el7.noarch
--> Processing Dependency: perl(Compress::Zlib) for package: perl-PlRPC-0.2020-14.el7.noarch
--> Running transaction check
---> Package perl-IO-Compress.noarch 0:2.061-2.el7 will be installed
--> Processing Dependency: perl(Compress::Raw::Zlib) >= 2.061 for package: perl-IO-Compress-2.061-2.el7.noarch
--> Processing Dependency: perl(Compress::Raw::Bzip2) >= 2.061 for package: perl-IO-Compress-2.061-2.el7.noarch
---> Package perl-Net-Daemon.noarch 0:0.48-5.el7 will be installed
--> Running transaction check
---> Package perl-Compress-Raw-Bzip2.x86_64 0:2.061-3.el7 will be installed
---> Package perl-Compress-Raw-Zlib.x86_64 1:2.061-4.el7 will be installed
--> Finished Dependency Resolution

 
         

Dependencies Resolved

 
         

==================================================================================================================================================================================================================
Package Arch Version Repository Size
==================================================================================================================================================================================================================
Installing:
mysql-community-libs x86_64 5.6.41-2.el7 mysql56-community 2.0 M
replacing mariadb-libs.x86_64 1:5.5.56-2.el7
mysql-community-server x86_64 5.6.41-2.el7 mysql56-community 59 M
Installing for dependencies:
libaio x86_64 0.3.109-13.el7 base 24 k
mysql-community-client x86_64 5.6.41-2.el7 mysql56-community 19 M
mysql-community-common x86_64 5.6.41-2.el7 mysql56-community 257 k
perl-Compress-Raw-Bzip2 x86_64 2.061-3.el7 base 32 k
perl-Compress-Raw-Zlib x86_64 1:2.061-4.el7 base 57 k
perl-DBI x86_64 1.627-4.el7 base 802 k
perl-Data-Dumper x86_64 2.145-3.el7 base 47 k
perl-IO-Compress noarch 2.061-2.el7 base 260 k
perl-Net-Daemon noarch 0.48-5.el7 base 51 k
perl-PlRPC noarch 0.2020-14.el7 base 36 k

 
         

Transaction Summary
==================================================================================================================================================================================================================
Install 2 Packages (+10 Dependent packages)

 
         

Total download size: 82 M

 

我們確定后開始安裝。

安裝完成后使用 /bin/systemctl start mysqld.service 啟動 MySQL 

然后 大功告成!

[root@iz2ze46vymskz5z22xevegz yum.repos.d]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.41 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

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.

完成安裝和啟動之后,我們可以在 /etc/my.conf 找到 MySQL 的配置文件, 默認數據存放位置是 /var/lib/mysql。

安裝好之后默認 root 賬戶是沒有密碼的。設置 root 的密碼使用

mysql> SET PASSWORD = PASSWORD('123456'); 

之后就是各自配置需要的內容即可!

 

下面再拿一節單獨講一下如何卸載 MySQL 因為可能因為安裝錯誤或者版本升級各種各樣的原因,我們需要卸載掉稚氣啊安安裝的 MySQL

使用 rpm -qa | grep mysql

找到目前已經安裝的跟 MySQL 相關的軟件包

 

rpm -e mysql-community-server-5.7.26-1.el7.x86_64
rpm -e mysql-community-client-5.7.26-1.el7.x86_64
如果還有一些驅動啥的就都卸載掉。

刪除對應需要刪除的軟件包

先使用 systetmctl list-unit-files | grep mysql 查看 MySQL 相關的服務
然后使用 chkconfig -del mysql 刪除相關的服務

刪除對應的服務

清理相關的 MySQL 文件文件夾
find / -name mysql  找到對應的位置刪除即可。

通用的五個地方是
/var/lib/mysql    存放數據的地方
/usr/share/mysql  不知道放什么的地方
/var/log/mysql/mysql-bin   binlog 存放位置
/var/log/mysql  錯誤日志
/etc/my.cnf   mysql 配置文件

其他的還是按照搜索出來的地方一一清除即可。

 

 

Reference:

https://dev.mysql.com/downloads/repo/yum/  Download MySQL Yum Repository

https://dev.mysql.com/doc/mysql-yum-repo-quick-guide/en/  A Quick Guide to Using the MySQL Yum Repository

https://support.ruckuswireless.com/articles/000002490  What is a GA release?

https://blog.csdn.net/alex_bean/article/details/55656236  CentOS 下完全卸載 MySQL

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM