「MySQL」- cannot be converted from type x to type y @20210224

Problem Description

In MySQL master-slave replication, the following error is generated:

Column 0 of table 'database_name.table_name' cannot be converted from type 'int' to type 'bigint(20)'

According to the prompt, the int type cannot be converted to the bigint type, but what is the reason?

System environment

Attributes parameter
MySQL Master-Master Replication
SELECT @@version; 5.7.20-log
SELECT @@binlog_format; ROW
SELECT @@slave_type_conversions;  

problem causes

First of all, the SQL statement of the database is written to the binary log after the execution is successful.

# In our scene

This is also a speculation: at that time the binary log of the main library was not fully synchronized to the slave library. We modified the fields of the slave library from int to bigint. And the database does not set the slave_type_conversions attribute, so type conversion is not allowed between master and slave. The binary log is in ROW format, and the fields in the binary log are of type int , but the target is of type bigint .

In addition, we turned on the log_slave_updates attribute, but no records from the main library were found in the binlog of the library.

Solution

The conversion from int to bigint is lossless, so you can set slave_type_conversions=ALL_NON_LOSSY .

Or do not perform these operations during binary log synchronization. In fact, we still have to understand some of the details in the database.

However, things have never been so simple. In the article " ERROR 1677: Column of table cannot be converted from type varchar(0) to type varchar(20) ", the author fixed the problem by executing REPAIR TABLE .

references

5.2.4.2. Setting The Binary Log Format
16.1.6.3 Replication Slave Options and Variables/slave_type_conversions
Row-based replication: attribute promotion and demotion.
Type conversion modes (slave_type_conversions variable).
MySQL Row-Based Binary Logs
Is MySQL Replication Affected by a High-Latency Interconnect?
MySQL binary log - write operation
4.1.10.2 Replication of Columns Having Different Data Types
MySQL Row-Based Binary Logs
ERROR 1677: Column of table cannot be converted from type varchar(0) to type varchar(20)

Guess you like

Origin blog.csdn.net/u013670453/article/details/114023802