【MySQL系列】Linux MySQL RPM包安装的升级方式

文章目录

  • 前言
      • MySQL-RPM的安装两种升级方式
        • 一、 第一种离线方式安装
          • 1.过滤出系统安装的MySQL相关的包
          • 2.根据过滤出来的包下载需要升级的包
          • 3.备份数据库
          • 4.停掉数据库
          • 5.卸载被替换的低版本myql
          • 6.安装mysql
          • 7.启动mysql
          • 8.利用mysql_upgrate进行系统表的检测
          • 9.进入到MySQL验证
        • 二、yum update 在线升级(推荐)
          • 1.备份数据库及文件
          • 2.过滤出系统安装的MySQL相关的包
          • 3.修改下载源
          • 4.yum update 进行数据库更新
          • 5.重启数据库
          • 6.利用mysql_upgrate进行系统表的检测
  • 总结


前言

这里介绍的是对于MySQL,RPM包升级的两种方式


提示:以下是本篇文章正文内容,来自生产案例,适用RPM包部署的MySQL

MySQL-RPM的安装两种升级方式

这里是基于MySQL5.7.29->MySQL5.7.37的案例来做讲解:

一、 第一种离线方式安装

1.过滤出系统安装的MySQL相关的包
[root@mysql ~]# rpm -qa|grep -i mysql
mysql-community-libs-5.7.29-1.el7.x86_64
mysql-community-server-5.7.29-1.el7.x86_64
mysql-community-common-5.7.29-1.el7.x86_64
mysql-community-libs-compat-5.7.29-1.el7.x86_64
mysql-community-devel-5.7.29-1.el7.x86_64
mysql-community-client-5.7.29-1.el7.x86_64
[root@mysql ~]# 
2.根据过滤出来的包下载需要升级的包

注意:根据需要下载对应相关的包,我这里是升级到5.7.37
推荐下载路径清华源,因为官方在国外,清华源是国内的访问速度快
地址:https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-5.7-community-el7-x86_64/

#我这里已经下载好了
[root@mysql mysql5737]# ll
总用量 212048
-rw-r--r-- 1 root root  26670472 1216 10:01 mysql-community-client-5.7.37-1.el7.x86_64.rpm
-rw-r--r-- 1 root root    318884 1216 10:01 mysql-community-common-5.7.37-1.el7.x86_64.rpm
-rw-r--r-- 1 root root   4122424 1216 10:01 mysql-community-devel-5.7.37-1.el7.x86_64.rpm
-rw-r--r-- 1 root root   2474780 1216 10:02 mysql-community-libs-5.7.37-1.el7.x86_64.rpm
-rw-r--r-- 1 root root   1264836 1216 10:02 mysql-community-libs-compat-5.7.37-1.el7.x86_64.rpm
-rw-r--r-- 1 root root 182274360 1216 10:02 mysql-community-server-5.7.37-1.el7.x86_64.rpm
3.备份数据库

根据实际情况选择备份方式,数据量大就用物理工具,数据小就用原生自带的即可,这里就不多做介绍

# 备份数据库
mysqldump  -u$MYSQL_ADMIN_USER -p $MYSQL_ADMIN_PASSWOR   --all-databases  --default-character-set=utf8  >  /data/backup/databases.sql
# 备份配置文件
cp /etc/my.cnf /etc/my.cnf.bak
4.停掉数据库
systemctl stop mysqld.service
5.卸载被替换的低版本myql
rpm -qa | grep -i mysql | xargs rpm -ev --nodeps
6.安装mysql
# 按照顺序执行
rpm -ivh mysql-community-common-5.7.37-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.37-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-compat-5.7.37-1.el7.x86_64.rpm
rpm -ivh mysql-community-devel-5.7.37-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.37-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.37-1.el7.x86_64.rpm
7.启动mysql
systemctl start mysqld.service
8.利用mysql_upgrate进行系统表的检测

解释:mysql_upgrate进行系统数据库表检测,检测是否兼容,如果发现问题,则试图对其进行修复

# 以下全是ok代表没有问题
[root@mysql mysql5737]# mysql_upgrade -u$MYSQL_ADMIN_USER -p $MYSQL_ADMIN_PASSWOR
mysql_upgrade: [Warning] Using a password on the command line interface can be insecure.
Checking if update is needed.
Checking server version.
Running queries to upgrade MySQL server.
Checking system database.
mysql.columns_priv                                 OK
mysql.db                                           OK
mysql.engine_cost                                  OK
mysql.event                                        OK
mysql.func                                         OK
mysql.general_log                                  OK
mysql.gtid_executed                                OK
mysql.help_category                                OK
mysql.help_keyword                                 OK
mysql.help_relation                                OK
mysql.help_topic                                   OK
mysql.innodb_index_stats                           OK
mysql.innodb_table_stats                           OK
mysql.ndb_binlog_index                             OK
mysql.plugin                                       OK
mysql.proc                                         OK
mysql.procs_priv                                   OK
mysql.proxies_priv                                 OK
mysql.server_cost                                  OK
mysql.servers                                      OK
mysql.slave_master_info                            OK
mysql.slave_relay_log_info                         OK
mysql.slave_worker_info                            OK
mysql.slow_log                                     OK
mysql.tables_priv                                  OK
mysql.time_zone                                    OK
mysql.time_zone_leap_second                        OK
mysql.time_zone_name                               OK
mysql.time_zone_transition                         OK
mysql.time_zone_transition_type                    OK
mysql.user                                         OK
The sys schema is already up to date (version 1.5.2).
Checking databases.
sys.sys_config                                     OK
Upgrade process completed successfully.
Checking if update is needed.
9.进入到MySQL验证

注意:如果数据有问题,可以利用备份好的sql文件,导入到数据库进行恢复

## 看到已经升级到指定版本
[root@mysql mysql5737]# mysql -uroot -p密码
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 3
Server version: 5.7.37 MySQL Community Server (GPL)

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

mysql> 

二、yum update 在线升级(推荐)

提示:这种方法很方便,通过指定mysql版本信息进行更新,没有第一种方式复杂,假如有自己的yum服务器,就上传至yum服务器,或者能连外网直接指定就行

1.备份数据库及文件
mysqldump  -u$MYSQL_ADMIN_USER -p $MYSQL_ADMIN_PASSWOR   --all-databases  --default-character-set=utf8  >  /data/backup/databases.sql
cp /etc/my.cnf /etc/my.cnf.bak
2.过滤出系统安装的MySQL相关的包
[root@mysql ~]# rpm -qa|grep -i mysql
mysql-community-libs-5.7.29-1.el7.x86_64
mysql-community-server-5.7.29-1.el7.x86_64
mysql-community-common-5.7.29-1.el7.x86_64
mysql-community-libs-compat-5.7.29-1.el7.x86_64
mysql-community-devel-5.7.29-1.el7.x86_64
mysql-community-client-5.7.29-1.el7.x86_64
[root@mysql ~]# 
3.修改下载源

提示:可以在此连接查询相关的版本信息包名https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-5.7-community-el7-x86_64/
一般yum源是无法直接进行指定更新,需要修改成清华源并且加一条路径(自己有yum服务器则不用,上传包yum服务器就像),如下:
提示:可以直接复制,先把原有的文件进行备份,替换完后需要执行以下操作

yum clean all
yum makecache
[root@mysql yum.repos.d]# cat CentOS-Base.repo
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.  You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#


[base]
name=CentOS-$releasever - Base
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-7

#released updates
[updates]
name=CentOS-$releasever - Updates
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/updates/$basearch/
baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-5.7-community-el7-x86_64/ 
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-7



#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/extras/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-7



#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/centosplus/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
gpgcheck=0
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-7

4.yum update 进行数据库更新
yum update -y  mysql-community-server-5.7.37-1.el7.x86_64 \
mysql-community-common-5.7.37-1.el7.x86_64 \
mysql-community-libs-5.7.37-1.el7.x86_64  \
mysql-community-libs-compat-5.7.37-1.el7.x86_64 \
mysql-community-devel-5.7.37-1.el7.x86_64  \
mysql-community-client-5.7.37-1.el7.x86_64 \

数据库已经更新成指定的版本了

[root@Template yum.repos.d]# rpm -qa|grep mysql
mysql-community-libs-5.7.37-1.el7.x86_64
mysql-community-devel-5.7.37-1.el7.x86_64
mysql-community-common-5.7.37-1.el7.x86_64
mysql-community-client-5.7.37-1.el7.x86_64
mysql-community-libs-compat-5.7.37-1.el7.x86_64
mysql-community-server-5.7.37-1.el7.x86_64

5.重启数据库
 systemctl restart mysqld.service
6.利用mysql_upgrate进行系统表的检测

注意:全是ok说明没有问题,进入数据库查看数据是否正常或者访问业务页面看是否正常,数据不正常可以利用备份好的sql文件进行恢复

[root@mysql yum.repos.d]# mysql_upgrade -uroot -pLK@szgdjzc2022.
mysql_upgrade: [Warning] Using a password on the command line interface can be insecure.
Checking if update is needed.
Checking server version.
Running queries to upgrade MySQL server.
Checking system database.
mysql.columns_priv                                 OK
mysql.db                                           OK
mysql.engine_cost                                  OK
mysql.event                                        OK
mysql.func                                         OK
mysql.general_log                                  OK
mysql.gtid_executed                                OK
mysql.help_category                                OK
mysql.help_keyword                                 OK
mysql.help_relation                                OK
mysql.help_topic                                   OK
mysql.innodb_index_stats                           OK
mysql.innodb_table_stats                           OK
mysql.ndb_binlog_index                             OK
mysql.plugin                                       OK
mysql.proc                                         OK
mysql.procs_priv                                   OK
mysql.proxies_priv                                 OK
mysql.server_cost                                  OK
mysql.servers                                      OK
mysql.slave_master_info                            OK
mysql.slave_relay_log_info                         OK
mysql.slave_worker_info                            OK
mysql.slow_log                                     OK
mysql.tables_priv                                  OK
mysql.time_zone                                    OK
mysql.time_zone_leap_second                        OK
mysql.time_zone_name                               OK
mysql.time_zone_transition                         OK
mysql.time_zone_transition_type                    OK
mysql.user                                         OK
The sys schema is already up to date (version 1.5.2).
Checking databases.
sys.sys_config                                     OK
Upgrade process completed successfully.
Checking if update is needed.
[root@mysql yum.repos.d]# 

总结

两种方法都是用于RPM安装mysql的升级方式,根据需要选择适合的方式进行升级,升级前一定要做好备份!!

你可能感兴趣的:(MySQL,mysql,linux,数据库)