Can’t I quickly import data after MySQL migration?

Notes on GTID related functions after upgrading from 5.6 to 5.7.

Author: Qin Fulang, a member of the DBA team of Aikesheng, responsible for handling daily project problems and troubleshooting company platform problems. A DBA who loves the Internet, knows photography, and knows cooking skills is not a good driver, didi~

Produced by the Aikeson open source community. Original content may not be used without authorization. Please contact the editor and indicate the source for reprinting.

This article has a total of 400 words and is expected to take 2 minutes to read.

background

A financial company has a system that has just been migrated from 5.6 to 5.7.30. GTID was not enabled before the migration, but GTID related functions were enabled after the migration. CREATE TABLE ... SELECT ...When the business uses imported data in the usual way, an error occurs: Error Code:1786 (HY000): Mysql Statement violates GTID consistency: CREATE TABLE ... SELECT.

Problem principle

This problem is relatively simple. The reason is that the migrated MySQL5.7 uses GTID and enables enforce_gtid_consistencyparameters (GTID strong consistency).

To ensure the consistency of distributed transactions, MySQL uses GTID to uniquely identify a transaction. In GTID mode, DDL and DML statements will automatically generate different GTIDs to identify different transaction operations. However, CREATE TABLE ... SELECT ...only one GTID is generated, and DDL and DML operations are merged into one transaction execution. This will cause master-slave data inconsistency when statement execution fails. Turning on enforce_gtid_consistencythe parameter is for the atomicity of GTID transactions.

The official documentation also explains CREATE TABLE ... SELECT ...this operation:

solution

For safety reasons, it is not recommended to turn this parameter off.

On MySQL5.7, you can solve this problem by splitting SQL into two sentences, such as:

#先创建表
CREATE TABLE ... LIKE...

#再插入数据
INSERT INTO ... SELECT ...

Although the previous single SQL can be easily and quickly derived to another table, it can be a little more troublesome for safety.

MySQL 8.0

The good news is that starting from MySQL8.0.21, storage engines that support atomic DDL allow the use of CREATE TABLE ... SELECT ...statements.

For more technical articles, please visit: https://opensource.actionsky.com/

About SQLE

SQLE from the Axon open source community is a SQL audit tool for database users and managers that supports multi-scenario audits, standardized online processes, native support for MySQL audits and scalable database types.

SQLE get

type address
Repository https://github.com/actiontech/sqle
document https://actiontech.github.io/sqle-docs/
release news https://github.com/actiontech/sqle/releases
Data audit plug-in development documentation https://actiontech.github.io/sqle-docs/docs/dev-manual/plugins/howtouse
Lei Jun: The official version of Xiaomi's new operating system ThePaper OS has been packaged. The pop-up window on the lottery page of Gome App insults its founder. Ubuntu 23.10 is officially released. You might as well take advantage of Friday to upgrade! Ubuntu 23.10 release episode: The ISO image was urgently "recalled" due to containing hate speech. A 23-year-old PhD student fixed the 22-year-old "ghost bug" in Firefox. RustDesk remote desktop 1.2.3 was released, enhanced Wayland to support TiDB 7.4 Release: Official Compatible with MySQL 8.0. After unplugging the Logitech USB receiver, the Linux kernel crashed. The master used Scratch to rub the RISC-V simulator and successfully ran the Linux kernel. JetBrains launched Writerside, a tool for creating technical documents.
{{o.name}}
{{m.name}}

Guess you like

Origin my.oschina.net/actiontechoss/blog/10119871