MySQL 5.6 upgrade to MySQL 5.7

I. Overview

There are two ways to upgrade MySQL from 5.6 to 5.7:

  • In-Place Upgrade
  • Logical Upgrade

Specific reference to the official website link: MySQL Upgrade Strategies

2. Upgrade operation

Taking the In-Place method, that is, physical upgrade as an example, the MySQL versions are 5.6.27 and 5.7.13 respectively.

The specific process is as follows:

  • Use xtrabackup to perform a full backup of 5.6 data
  • Install MySQL 5.7, copy the data files backed up by 5.6 to the data directory of 5.7
  • Upgrade 5.6 data files in 5.7
  • After the upgrade is completed, use 5.7 as the 5.6 on the synchronization line from the library
  • Find the right time to switch to the 5.7 slave library

1. Environmental preparation

Build a 5.7 instance and replace the 5.7 data directory with the backup of the 5.6 instance

mv data data_20180405            #移走5.7库data
mv 56_back_20180405 data         #移入5.6库备份文件
chown -R mysql.mysql data

2. Update data files

Open 5.7 instance

./bin/mysqld_safe --defaults-file=./etc/mysql.cnf &

After startup, you will find that the 5.7 instance can already be logged in at this time, but there will be many errors in the error log:

[ERROR] Incorrect definition of table performance_schema.events_waits_current: expected column 'NESTING_EVENT_TYPE' at position 15 to have type enum('TRANSACTION','STATEMENT','STAGE','WAIT', found type enum('STATEMENT','STAGE','WAIT').
[ERROR] Incorrect definition of table performance_schema.events_waits_summary_by_user_by_event_name: expected column 'USER' at position 0 to have type char(32), found type char(16).
[ERROR] Column count of performance_schema.table_lock_waits_summary_by_table is wrong. Expected 68, found 73. Created with MySQL          50627, now running 50713. Please use mysql_upgrade to fix this error.
[ERROR] mysql.user has no `Event_priv` column at position 28
[ERROR] Native table 'performance_schema'.'session_variables' has the wrong structure
...

The following uses the 5.7 instance to upgrade the 5.6 data file:

./bin/mysql_upgrade --defaults-extra-file=./etc/user.root.cnf
  • This operation will check the system table and upgrade, and check all library table compatibility.

3. Restart the 5.7 instance

./bin/mysqladmin --defaults-extra-file=./etc/user.root.cnf shutdown
./bin/mysqld_safe --defaults-file=./etc/mysql.cnf &

Checking the error log at this time, you will find that the startup process is normal this time, and no error is reported.

So far, the data files of the 5.6 instance have been successfully upgraded.

4. Establish master-slave synchronization for switching

Since 5.7 uses the full backup of 5.6, synchronization can be established by specifying the synchronization point in xtrabackup_binlog_info, and 5.7 can be used as the slave library of 5.6.

After the synchronization check is OK, you can find a suitable time to switch. The specific steps related to handover will not be described in detail. You can choose to use MHA or manual handover during low business peak periods.

3. Related issues

1. Cannot setup server variables

Encountered when using mysql_upgrade to upgrade:

./bin/mysql_upgrade --defaults-extra-file=./etc/user.root.cnf
Error occurred: Cannot setup server variables.

This is because the account I am using at this time is a normal account without super permission, and the problem is solved after changing to an account with super permission.

4. Postscript

The method provided on the MySQL official website is shutdown 5.6, replace binary packages and commands with the 5.7 version, and then perform the upgrade operation, but this method requires shutdown DB, which may not be applicable to online, so the reverse is better.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324370568&siteId=291194637