升级:Logical Upgrade升级MySQL5.6.26

升级需谨慎,事前先备份

MySQL升级的实质是对数据字典的升级,数据字典有:sys、mysql、information_schema、performance_schema 。

 

MySQL升级的两种方式:

1、in-place upgrade(适合小版本的升级)

关闭当前的MySQL,替换原来的安装目录和my.cnf配置文件,mysql_upgrade脚本升级数据字典,在现有的数据目录上重启MySQL,


特点:不改变数据文件,升级速度快;这种方式先停掉数据库,在进行升级操作,所以停机时间长;但,不可以跨操作系统,不可以跨大版本(5.5—>5.7).

2、logical upgrade(适合不同操作系统的MySQL升级,大版本之间的升级)

使用mysqldump 或 mydumper 导入导出数据,实现版本的升级。可以利用gtid或者主从增量恢复数据。

 

特点:可以跨操作系统,跨大版本,整理表碎片;但,数据量大的情况下升级速度慢,容易出现乱码等问题。升级时间长,但是切换时间短

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

 

1.升级方法介绍

本文测试准备了新的mysql服务器来承接迁移的数据库,很多细节没有做测试,比如最后增量数据没有做同步,也没做端口变更,只是做迁移数据和升级了数据库。这种也可以做成单台服务器多个实例做迁移,然后搭建主从恢复增量数据,最后做切换。

ip:192.168.163.21->192.168.163.20

mysql:5.6.29->5.7.29

2.升级步骤

2.1操作之前,查看版本

[root@rhel7 mysql5.7]# /app/mysql5.7/bin/mysql -V
/app/mysql5.7/bin/mysql  Ver 14.14 Distrib 5.7.32, for linux-glibc2.12 (x86_64) using  EditLine wrapper

 

 

 

2.2利用mysqldump导出数据

利用mysqldump工具,从mysql 5.6.26导出数据:
mysqldump -uroot -p --default-character-set=utf8 --all-databases --single-transaction --routines --triggers --events --master-data=2 -S /data/mysql/mysql4406/tmp/mysql4406.sock --set-gtid-purged=off > /tmp/full_20210208.sql

 

 

2.3停掉MySQL 5.6的数据库并备份MySQL 5.6软件目录

将旧版本MySQL 5.6的数据库关闭并备份原来的数据目录。
[root@rhel7 /]# cp -rp /data /data56

[root@rhel7 /]# cp /etc/init.d/mysql mysql56

[root@rhel7 /]# cp -rp /usr/local/mysql /usr/local/mysql56

 

2.4建立新版本的数据目录并授权

这一步选用了一个新的服务器来承接旧的mysql业务,所以在新的服务器上搭建mysql5.7版本

 

[root@mysql-test ~ 13:41:48]# mkdir -p /data/3309

[root@mysql-test ~ 13:41:57]# mkdir -p /application/

[root@mysql-test ~ 13:42:09]# chown -R mysql.mysql /data/

 

 

 

 

 

2.5替换MySQL的安装文件

需要执行unlink mysql命令,取消链接到MySQL 5.6.26版本的链接文件,或者重新直接mv。
解压新版本的MySQL软件包,然后重新做链接并赋予MySQL权限。命令如下:

[root@mysql-test ~ 13:42:09]# tar -zxvf mysql-5.7.32-linux-glibc2.12-x86_64.tar.gz

[root@mysql-test ~ 13:42:09]# mv mysql-5.7.32-linux-glibc2.12-x86_64.tar.gz /application/mysql

[root@mysql-test ~ 13:42:00]# chown -R mysql.mysql /application/

 

 

 

 

2.6替换参数文件并初始化数据库

替换MySQL 5.6的配置文件为MySQL 5.7版本的my.cnf文件,并初始化数据库。 命令如下:
/application/mysql/bin/mysqld --defaults-file=/data/3309/my.cnf --basedir=/application/mysql --datadir=/data/3309/data -initialize

mysql5.6的参数文件移动到mysql5.7中来

scp /data/mysql/mysql4406/etc/my4406.cnf root@192.168.163.20:/data/3309/my.cnf

 

 

 

[root@mysql-test /data/3309 13:52:26]# chown -R mysql.mysql my.cnf

 

 

 

 

2.7启动新版本MySQL

[root@mysql-test /application/mysql 13:35:19]# /application/mysql/bin/mysql -uroot -p -S /data/3309/mysql.sock

 

 

 

 

mysql启动加入系统服务systemctl status mysqld3309.service

cat >> /etc/systemd/system/mysqld3309.service EOF

[Unit]

Description=MySQL Server

Documentation=man:mysqld(8)

Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html

After=network.target

After=syslog.target

[Install]

WantedBy=multi-user.target

[Service]

User=mysql

Group=mysql

ExecStart=/application/mysql/bin/mysqld --defaults-file=/data/3309/my.cnf

LimitNOFILE = 5000

EOF

 

服务启动方式

[root@mysql-test /data/3309 14:03:02]# systemctl start mysqld3309.service

[root@mysql-test /data/3309 14:03:07]# systemctl status mysqld3309.service

 

 

 

 

 

2.8导入从MySQL 5.6导出的文件到新版本数据库中

mysql5.6的数据全部备份

[mysql@rhel7 ~]$ mysqldump -uroot -p --default-character-set=utf8 --all-databases --single-transaction --routines --triggers --events --master-data=2 -S /data/mysql/mysql4406/tmp/mysql4406.sock --set-gtid-purged=off > /tmp/full_20210208.sql

 

 

 

命令如下,mysql5.6的数据移动到mysql5.7的服务器中来

 

 

 

mysql5.7中将数据恢复
[mysql@mysql-test /usr/local ]$ mysql -uroot -p -S /data/3309/mysql.sock < /tmp/full_20210208.sql

 

 

 

2.9升级系统表数据字典信息

命令如下:
[mysql@mysql-test /usr/local ]$ mysql_upgrade -uroot -p -S /data/3309/mysql.sock
输出结果:

[mysql@mysql-test /usr/local ]$ mysql_upgrade -uroot -p -S /data/3309/mysql.sock

Enter password:

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).

Found 0 sys functions, but expected 22. Re-installing the sys schema.

Upgrading the sys schema.

Checking databases.

oldboy.t1                                          OK

sys.sys_config                                     OK

Upgrade process completed successfully.

Checking if update is needed.

 

 

 

没有报错,表示系统表数据字典信息升级成功。

2.10重启MySQL服务

[root@mysql-test /application/mysql 13:36:26]# systemctl restart mysqld3309.service

[root@mysql-test /application/mysql 13:36:35]# systemctl status mysqld3309.service

 

 

 

2.11验证MySQL版本

目前己经是MySQL5.7版本,证明升级成功:
[root@mysql-test /tmp 13:25:28]# /usr/local/mysql/bin/mysql -V
/usr/local/mysql/bin/mysql Ver 14.14 Distrib 5.7.20, for linux-glibc2.12 (x86_64) using EditLine wrapper

 

 

 

 

 

posted @ 2021-02-10 09:37  我爱睡莲  阅读(230)  评论(0编辑  收藏  举报