mysql 升级意义_MySQL升级

升级MySQL5.7 -> MySQL 8.0

Xtrabackup 备份恢复数据

**备份:**

innobackupex --defaults-file=/etc/my.cnf --user=root --password=123456 /path/to/BACKUP-DIR/

**恢复:**

innobackupex --apply-log /backups/2018-07-30_11-04-55/

innobackupex --defaults-file=/etc/my.cnf --copy-back /backups/2018-07-30_11-04-55/

$ chown -R mysql:mysql /path/the/datadir

**备份**

xtrabackup --backup --target-dir=/data/backups/ --user=root --password=123456

**恢复**

xtrabackup --prepare --target-dir=/data/backups/

xtrabackup --copy-back --target-dir = / data / backups /

$ chown -R mysql:mysql /path/the/datadir

MySQL 5.7 创建压测的时候进行xtrabackup 备份

1.准备工作

sysbench --db-driver=mysql --mysql-table-engine=innodb --mysql-host=127.0.0.1 --mysql-port=3336 --mysql-db=sbtest --mysql-user='sbtest' --mysql-password='123' --test=/usr/share/sysbench/tests/include/oltp_legacy/oltp.lua --oltp-table-ize=5000000 --oltp-tables-count=8 --num-threads=16 --max-time=1800 --max-requests=0 --report-interval=3 prepare

2. 压测的同时进行xtrabackup模拟并发时进行备份:

sysbench --db-driver=mysql --mysql-table-engine=innodb --mysql-host=127.0.0.1 --mysql-port=3336 --mysql-db=sbtest --mysql-user='sbtest' --mysql-password='123' --test=/usr/share/sysbench/tests/include/oltp_legacy/oltp.lua --oltp-table-ize=5000000 --oltp-tables-count=8 --num-threads=16 --max-time=1800 --max-requests=0 --report-interval=3 run

innobackupex --defaults-file=/etc/my3336.cnf --user=root --password=123 /mysqldata/bak/

3.对备份文件进行–apply-log

innobackupex --apply-log /mysqldata/bak/2020-09-03_15-13-54/

将数据恢复至MySQL8.0的数据库中

测试数据库版本为MySQL 5.7.28 升级至 MySQL8.0.21

尝试—copy-back将目录恢复至MySQL8.0的数据目录中

使用MySQL8.0对应版本的Xtrabackup8.0.14的版本进行恢复,会发生如下报错:

命令:xtrabackup --defaults-file=/etc/my3308.cnf --copy-back --target-dir=/mysqldata/bak/2020-09-03_15-13-54/

[root@balabala local]# xtrabackup --defaults-file=/etc/my3308.cnf --copy-back --target-dir=/mysqldata/bak/2020-09-03_15-13-54/

xtrabackup: recognized server arguments: --server-id=3308 --datadir=/mysqldata/my3308/data1 --tmpdir=/mysql/tmp3308 --innodb_data_home_dir=/mysqldata/my3308/data --log_bin=/mysqldata/my3308/log/mysql-bin --log-bin-index=/mysqldata/my3308/log/mysql-bin.index --innodb_flush_method=O_DIRECT --innodb_flush_log_at_trx_commit=1

xtrabackup: recognized client arguments: --socket=/mysql/my3308/mysql.sock --port=3308 --copy-back=1 --target-dir=/mysqldata/bak/2020-09-03_15-13-54/

xtrabackup version 8.0.14 based on MySQL server 8.0.21 Linux (x86_64) (revision id: 113f3d7)

xtrabackup: Error: cannot open file './xtrabackup_tablespaces'

xtrabackup: Error: failed to load tablespaces list.

It is possible that the backup was created by Percona XtraBackup 2.4 or earlier version. Please use the same XtraBackup version to restore.

使用MySQL5.7的备份工具进行恢复到指定的数据目录:

命令:innobackupex --defaults-file=/etc/my3336.cnf --copy-back /mysqldata/bak/2020-09-03_15-13-54/

[root@balabala my3308]# innobackupex --defaults-file=/etc/my3308.cnf --copy-back /mysqldata/bak/2020-09-03_15-13-54/

xtrabackup: recognized server arguments: --server-id=3308 --datadir=/mysqldata/my3308/data --tmpdir=/mysql/tmp3308 --innodb_data_home_dir=/mysqldata/my3308/data --log_bin=/mysqldata/my3308/log/mysql-bin --innodb_flush_method=O_DIRECT --innodb_flush_log_at_trx_commit=1

xtrabackup: recognized client arguments:

200903 15:39:16 innobackupex: Starting the copy-back operation

IMPORTANT: Please check that the copy-back run completes successfully.

At the end of a successful copy-back run innobackupex

prints "completed OK!".

innobackupex version 2.4.19 based on MySQL server 5.7.26 Linux (x86_64) (revision id: c2d69da)

200903 15:39:16 [01] Copying ib_logfile0 to /mysqldata/my3308/data/ib_logfile0

200903 15:39:17 [01] ...done

...

...

...

200903 15:39:22 [01] Copying ./xpp/t.ibd to /mysqldata/my3308/data/xpp/t.ibd

200903 15:39:22 [01] ...done

200903 15:39:22 completed OK!

尝试使用MySQL 8.0启动对应的数据目录

[root@balabala my3308]# chown -R mysql:mysql /mysqldata/my3308/data

[root@balabala my3308]# mysqld_safe --defaults-file=/etc/my3308.cnf --user=mysql&

查看错误日志:

2020-09-03T15:46:59.460306+08:00 0 [System] [MY-010931] [Server] /usr/local/mysql/bin/mysqld: ready for connections. Version: '8.0.21' socket: '/mysql/my3308/mysql.sock' port: 3308 MySQL Community Server - GPL.

如上,ready for connections表示数据库已经完全开启。

尝试创建数据库测试可用性:

[root@balabala my3308]# mysql -u root -S /mysql/my3308/mysql.sock -p123

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 8

Server version: 8.0.21 MySQL Community Server - GPL

Copyright (c) 2000, 2020, 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.

mysql> create database spp;

Query OK, 1 row affected (0.01 sec)

至此,升级完成。

此外:

对于之前版本的升级需要在使用老版本回复出来的数据目录使用mysql_upgrade程序进行表空间的升级,对于mysql 8.0.16以上版本不再需要 mysql_upgrade并已弃用,mysql_upgrade所执行的任务有mysql服务器执行。即不再需要额外执行mysql_upgrade检查和升级表。

174bdb6097b39971a0957882e8e87754.png

34fb77da8105bbb12a9d2131d6fbfac3.png

%E6%88%AA%E5%B1%8F2020-09-03%20%E4%B8%8B%E5%8D%884.18.44.png

现在不建议使用mysql_upgrade客户端。升级客户端执行的操作现在由服务器完成。

要升级,请使用较旧的数据目录启动新的MySQL二进制文件。修复用户表是自动完成的。升级后不需要重新启动。

升级过程会在运行带有旧数据目录的新MySQL二进制文件时自动开始。为避免意外升级,请对MySQL二进制文件使用–upgrade = NONE选项。还提供了选项–upgrade = FORCE来按需运行服务器升级序列。

由于多种原因,服务器升级可能会失败。在这种情况下,升级序列将在下一次MySQL服务器启动期间再次运行。如果服务器升级反复失败,则可以使用–upgrade = MINIMAL选项启动服务器,以在不执行升级序列的情况下启动服务器,从而允许用户手动解决问题。

注意:MySQL5.6不可以直接升级MySQL8.0,需要先升级MySQL 5.7再升级至MySQL 8.0

MySQL 5.6 -> MySQL 5.7

可以采用In-Place Upgrade的方式进行MySQL 5.6 到 MySQL 5.7的升级,如下:

使用MySQL5.7版本包中的mysqld_safe程序指定数据目录并启动数据库:

mysql5.7/bin/mysqld_safe --defaults-file=/etc/my3337.cnf --user=mysql &

mysql5.7/bin/mysql_upgrade -u root -p123 -S /tmp/mysql3337.sock

重启数据库,确保对系统表所做的变更生效:

mysql5.7/bin/mysqladmin -u root -p123 -S /tmp/mysql337.sock shutdown

mysql5.7/bin/mysqld_safe --defaults-file=/etc/my3337.cnf --user=mysql &

进入数据库,检查此时的数据库版本

mysql>select @@version;

+------------+

| @@version |

+------------+

| 5.7.28-log |

+------------+

1 row in set (0.00 sec)

升级MySQL5.7完成

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值