• 如何使用 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

  • 相关阅读:
    Servlet程序开发-- 过滤器
    English--Computer System
    Servlet程序开发--实例操作:MVC设计模式应用
    Servlet程序开发--WEB开发模式(Mode I, Mode II)
    在服务器上搭建git仓库
    git 搭建本地仓库
    smartcrop.js 内容感知图像裁剪
    js函数 eql,equal,equalp
    nodejs XML和json互相转换
    js 创建XML
  • 原文地址:https://www.cnblogs.com/piperck/p/9768024.html
Copyright © 2020-2023  润新知