mysql5.7.27 upgrade mysql8.0.16

mysql5.7 upgrade mysql8

Description:

1. This upgrade is based on the binary installation package of mysql5.7.27, which can avoid a long time of source code compilation.
2. You can upgrade directly from MySQL5.7 to 8.0, but only between the General Availability (GA) version , And then only 5.7.9 and above are supported. If it is a non-GA version, then direct upgrade is not supported.
3. Cross-version upgrade is not supported, such as upgrading from 5.6 to 8.0.

Before upgrading:

Version 5.7.27
has the database wg_qc_common; wg_qc_sm_9
has data in the
database There are other users in the database
Upgrade steps:

step1: Download the binary installation package of mysql8.0.16 and upload the specified directory
下载地址:https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.16-linux-glibc2.12-x86_64.tar.xz

Insert picture description here

step2: Unzip to the specified directory and change the attributes of the installation package
cd /root/
tar -xf mysql-8.0.16-linux-glibc2.12-x86_64.tar.xz -C /usr/local/ && cd /usr/local/
mv mysql-8.0.16-linux-glibc2.12-x86_64 mysql8 && chown -R mysql.mysql mysql8
step3: Manually check whether the upgrade conditions are met
1) The following problems must not occur

The table must not contain obsolete data types or functions. There
must not be a .frm file to
ensure that the trigger trigger must have no missing or empty definitions or invalid definitions (through the SHOW TRIGGERS or INFORMATION_SCHEMA TRIGGERS table, you can check the character_set_client in the trigger, collation_connection, the value of Database Collation)

cd /usr/local/mysql57/bin
./mysqlcheck -u root -p --all-databases --check-upgrade

Insert picture description here

2) Partition table

Make sure that you do not use the partition table of a storage engine that does not support native partitioning. You can query it with the following command:

SELECT TABLE_SCHEMA, TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
WHERE ENGINE NOT IN ('innodb', 'ndbcluster') AND CREATE_OPTIONS LIKE '%partitioned%';

Insert picture description here
If there are results returned, then the partition table must be the innodb storage engine, or change to a non-partitioned table.
Change the storage engine of the table:

ALTER TABLE table_name ENGINE = INNODB;

Change the partition table to a non-partition table:

ALTER TABLE table_name REMOVE PARTITIONING;
3) Table name and data dictionary nouns

Make sure not to have a table with the same name as the data dictionary in 8.0 in the MySQL system database of MySQL 5.7.
The following SQL query can be used:

SELECT TABLE_SCHEMA, TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES
WHERE LOWER(TABLE_SCHEMA) = 'mysql'
and LOWER(TABLE_NAME) IN
(
'catalogs',
'character_sets',
'collations',
'column_type_elements',
'columns',
'events',
'foreign_key_column_usage',
'foreign_keys',
'index_column_usage',
'index_partitions',
'index_stats',
'indexes',
'parameter_type_elements',
'parameters',
'routines',
'schemata',
'st_spatial_reference_systems',
'table_partition_values',
'table_partitions',
'table_stats',
'tables',
'tablespace_files',
'tablespaces',
'triggers',
'version',
'view_routine_usage',
'view_table_usage'
);

Insert picture description here
If there is such a table, it must be renamed. Such as:
LOCK TABLE old_table1 WRITE; --If data is written, the table can be temporarily locked.
Alter TABLE old_table1 RENAME new_table1
Note: The application also needs to be modified accordingly, otherwise it will cause unnecessary trouble

4) Foreign key constraint name

Make sure that there is no table whose foreign key constraint name exceeds 64 characters, which can be viewed through the following SQL:

SELECT CONSTRAINT_SCHEMA, TABLE_NAME,CONSTRAINT_NAME
FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS 
WHERE LENGTH(CONSTRAINT_NAME) > 64;

Insert picture description here
If there is, then modify it. Such as:

ALTER TABLE tbl_name DROP FOREIGN KEY fk_symbol;
5) Tables not supported by Mysql8 should be migrated to InnoDB

Before updating to 8.0.13 or higher, make sure that no table partitions are stored in the InnoDB table space, including system table spaces and general table spaces. Can be queried by the following SQL

SELECT DISTINCT NAME, SPACE, SPACE_TYPE 
FROM INFORMATION_SCHEMA.INNODB_SYS_TABLES 
WHERE NAME LIKE '%#P#%' AND SPACE_TYPE NOT LIKE 'Single';

Insert picture description here
If so, move the table from the shared table space to its own table space (innodb-file-per-table ), such as:

ALTER TABLE table_name REORGANIZE PARTITION partition_name 
INTO (partition_definition TABLESPACE=innodb_file_per_table);
step4: Back up the original database
1) Quickly close the warehouse

If the current environment is configured with cold shutdown (innodb_fast_shutdown = 2), then you need to change to fast or slow shutdown, such as:

SET GLOBAL innodb_fast_shutdown = 1; --快关闭
SET GLOBAL innodb_fast_shutdown = 0; --慢关闭

Through fast or slow shutdown, InnoDB keeps its undo log and data files in a state that can be processed in the case of file format differences between release versions.

SET GLOBAL innodb_fast_shutdown=0;  这里选择慢关闭

Insert picture description here

2) Stop the database and backup
/etc/init.d/mysqld stop    #关闭数据库
或者
cd /usr/local/mysql57/bin 
./mysqladmin -u root -p shutdown #关闭数据库(涉及主从同步的话,建议先关闭主从同步进程,再停掉主数据库)
ps -ef | grep mysqld | grep -v grep               #确认不存在mysql进程
cp -rf -p /u01/mysql/data /u01/mysql/data_5.7     #备份数据文件
cp -p /etc/my.cnf /etc/my.cnf_5.7                 #备份配置文件
cp -p /etc/init.d/mysqld /etc/init.d/mysqld_5.7   #备份启停脚本

Insert picture description here

step5: Modify the configuration file (/etc/my.cnf)
“basedir = /usr/local/mysql     #替换成“basedir = /usr/local/mysql8”
lower_case_table_names = 1      #(mysql5.7有,检查下)
skip-grant-tables  				#不添加,后期会用到
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION,NO_AUTO_CREATE_USER   #不添加,后期会用到
query_cache_size = 64M           #注释掉
query_cache_limit = 2M           #注释掉
query_cache_type  = 2            #注释掉
query_cache_min_res_unit = 2k    #注释掉
default_table_type = InnoDB      #注释掉
step6: Upgrade the database
1) In the new upgrade method of MySQL 8.0.16, a new option –upgrade is added to mysqld. The optional values ​​are NONE, AUTO, MINIMAL, FORCE.
NONE:不尝试进行升级
AUTO:默认选项,MySQL 进行数据字典升级和服务升级
MINIMAL:仅升级数据字典
FORCE:强制升级,类似旧的 mysql_upgrade –force
2) The new upgrade method of MySQL 8.0.16 is generally divided into 2 steps
1> Upgrade data dictionary (DD)
2> Server upgrade: upgrade MySQL system table, upgrade user table, upgrade sys table, upgrade help update table
cd /usr/local/mysql8/bin
./mysqld --upgrade=AUTO
3) Close the database
cd /usr/local/mysql8/bin
./mysqladmin -uroot -p -S /tmp/mysql.sock shutdown
4) Copy the startup script
cp -p support-files/mysql.server /etc/init.d/mysqld
step7: restart the database
/etc/init.d/mysqld restart
step8: Add the mysql command to the environment variable (/etc/profile) and verify the upgraded version
export PATH=$PATH:/usr/local/mysql8/bin
source /etc/profile

Insert picture description here

step9: Verify data integrity

Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_44729138/article/details/105614669