GreatSQL从库13146错误:字符集不一致问题的解决办法
1.问题总体情况
需要把数据反向同步到源端,在运用SELECT INTO OUTFILE
与LOAD DATA
进行数据恢复后配置同步时,从库出现13146数据类型转换失败的报错,致使同步出现异常;经过对比主从库相关表以及列的字符集,发现主从库对应表、列的字符集设置不一样,将其调整为一致后,同步恢复正常。
2.问题重现
本次测试基于 GreatSQL 8.0.32 版本
2.1 初始化两个单机实例
略
2.2 主库创建测试表
greatsql> CREATE TABLE `smbms_address` (
`id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
`contact` varchar(15) DEFAULT NULL COMMENT '联系人姓名',
`addressDesc` varchar(50) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL COMMENT '收货地址明细',
`postCode` varchar(15) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL COMMENT '邮编',
`tel` varchar(20) DEFAULT NULL COMMENT '联系人电话',
`createdBy` bigint DEFAULT NULL COMMENT '创建者',
`creationDate` datetime DEFAULT NULL COMMENT '创建时间',
`modifyBy` bigint DEFAULT NULL COMMENT '修改者',
`modifyDate` datetime DEFAULT NULL COMMENT '修改时间',
`userId` bigint DEFAULT NULL COMMENT '用户ID',
PRIMARY KEY (`id`));
greatsql> INSERT INTO `smbms_address`(`id`,`contact`,`addressDesc`,`postCode`,`tel`,`createdBy`,`creationDate`,
`modifyBy`,`modifyDate`,`userId`) values
(1,'小丽','北京市','100010','13689999',1,'2016-04-13 10:09:00',NULL,NULL,201),
(2,'小张','北京市','100000','185672312',1,'2016-04-13 01:10:32',NULL,NULL,201);
2.3 查看数据
greatsql> SELECT * FROM smbms_address;
+----+---------+-------------+----------+-----------+-----------+---------------------+----------+------------+--------+
| id | contact | addressDesc | postCode | tel | createdBy | creationDate | modifyBy | modifyDate | userId |
+----+---------+-------------+----------+-----------+-----------+---------------------+----------+------------+--------+
| 1 | 小丽 | 北京市 | 100010 | 13689999 | 1 | 2016-04-13 10:09:00 | NULL | NULL | 201 |
| 2 | 小张 | 北京市 | 100000 | 185672312 | 1 | 2016-04-13 01:10:32 | NULL | NULL | 201 |
+----+---------+-------------+----------+-----------+-----------+---------------------+----------+------------+--------+
2 rows in set (0.00 sec)
2.4 主库导出数据
greatsql> SELECT * FROM test01.smbms_address INTO OUTFILE '/data/smbms_address.txt' FIELDS TERMINATED BY '_~' ENCLOSED BY '"';
2.5 从库创建表
greatsql> CREATE TABLE `smbms_address` (
`id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
`contact` varchar(15) DEFAULT NULL COMMENT '联系人姓名',
`addressDesc` varchar(50) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL COMMENT '收货地址明细',
`postCode` varchar(15) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL COMMENT '邮编',
`tel` varchar(20) DEFAULT NULL COMMENT '联系人电话',
`createdBy` bigint DEFAULT NULL COMMENT '创建者',
`creationDate` datetime DEFAULT NULL COMMENT '创建时间',
`modifyBy` bigint DEFAULT NULL COMMENT '修改者',
`modifyDate` datetime DEFAULT NULL COMMENT '修改时间',
`userId` bigint DEFAULT NULL COMMENT '用户ID',
PRIMARY KEY (`id`));
2.6 从库导入数据
greatsql> LOAD DATA INFILE '/data/smbms_address.txt' INTO TABLE test01.smbms_address FIELDS TERMINATED BY '_~' ENCLOSED BY '"';
2.7 从库查询数据
greatsql> SELECT * FROM smbms_address;
+----+---------+-------------+----------+-----------+-----------+---------------------+----------+------------+--------+
| id | contact | addressDesc | postCode | tel | createdBy | creationDate | modifyBy | modifyDate | userId |
+----+---------+-------------+----------+-----------+-----------+---------------------+----------+------------+--------+
| 1 | 小丽 | 北京市 | 100010 | 13689999 | 1 | 2016-04-13 10:09:00 | NULL | NULL | 201 |
| 2 | 小张 | 北京市 | 100000 | 185672312 | 1 | 2016-04-13 01:10:32 | NULL | NULL | 201 |
+----+---------+-------------+----------+-----------+-----------+---------------------+----------+------------+--------+
2 rows in set (0.00 sec)
2.8 从库建立复制
#主库查看当前gtid和pos位点信息
greatsql> SHOW MASTER STATUS;
+---------------+----------+--------------+------------------+------------------------------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+---------------+----------+--------------+------------------+------------------------------------------+
| binlog.000001 | 1693 | | | 28093c86-5631-11ef-87f4-00163eab83df:1-2 |
+---------------+----------+--------------+------------------+------------------------------------------+
1 row in set (0.00 sec)
#从库执行
greatsql> RESET MASTER;
Query OK, 0 rows affected (0.04 sec)
greatsql>RESET SLAVE ALL;
Query OK, 0 rows affected, 1 warning (0.03 sec)
greatsql> SET GLOBAL GTID_PURGED='28093c86-5631-11ef-87f4-00163eab83df:1-2';
Query OK, 0 rows affected (0.00 sec)
greatsql> CHANGE MASTER TO MASTER_HOST = '172.17.140.13',MASTER_USER = 'replabc',MASTER_PASSWORD = '!QAZ2WSX',MASTER_PORT = 5506, MASTER_LOG_FILE='binlog.000001', MASTER_LOG_POS=1693;
Query OK, 0 rows affected, 8 warnings (0.05 sec)
greatsql> START SLAVE;
Query OK, 0 rows affected, 1 warning (0.04 sec)
greatsql> SHOW SLAVE STATUS \G
*************************** 1. row ***************************
Slave_IO_State: Waiting for source to send event
Master_Host: 172.17.140.13
Master_User: replabc
Master_Port: 5506
Connect_Retry: 60
Master_Log_File: binlog.000001
Read_Master_Log_Pos: 1693
Relay_Log_File: gip-relay-bin.000002
Relay_Log_Pos: 323
Relay_Master_Log_File: binlog.000001
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 1693
Relay_Log_Space: 531
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 135506
Master_UUID: 28093c86-5631-11ef-87f4-00163eab83df
Master_Info_File: mysql.slave_master_info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Replica has read all relay log; waiting for more updates
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set: 28093c86-5631-11ef-87f4-00163eab83df:1-2,
cea38b81-6b2a-11ef-926f-00163e8c8b06:1-2
Auto_Position: 0
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
Master_public_key_path:
Get_master_public_key: 0
Network_Namespace:
1 row in set, 1 warning (0.01 sec)
2.9 主库插入新数据
greatsql> INSERT INTO smbms_address values(3,'小小','北京市','100021','133876742',1,'2016-04-13 00:00:05',NULL,NULL,201);
2.10 从库查看复制状态
greatsql> SHOW SLAVE STATUS \G
*************************** 1. row ***************************
Slave_IO_State: Waiting for source to send event
Master_Host: 172.17.140.13
Master_User: replabc
Master_Port: 5506
Connect_Retry: 60
Master_Log_File: binlog.000001
Read_Master_Log_Pos: 2213
Relay_Log_File: gip-relay-bin.000002
Relay_Log_Pos: 323
Relay_Master_Log_File: binlog.000001
Slave_IO_Running: Yes
Slave_SQL_Running: No
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 13146
Last_Error: Coordinator stopped because there were error(s) in the worker(s). The most recent failure being: Worker 1 failed executing transaction '28093c86-5631-11ef-87f4-00163eab83df:3' at master log binlog.000001, end_log_pos 2182. See error log and/or performance_schema.replication_applier_status_by_worker table for more details about this failure or others, if any.
Skip_Counter: 0
Exec_Master_Log_Pos: 1693
Relay_Log_Space: 1051
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: NULL
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 13146
Last_SQL_Error: Coordinator stopped because there were error(s) in the worker(s). The most recent failure being: Worker 1 failed executing transaction '28093c86-5631-11ef-87f4-00163eab83df:3' at master log binlog.000001, end_log_pos 2182. See error log and/or performance_schema.replication_applier_status_by_worker table for more details about this failure or others, if any.
Replicate_Ignore_Server_Ids:
Master_Server_Id: 135506
Master_UUID: 28093c86-5631-11ef-87f4-00163eab83df
Master_Info_File: mysql.slave_master_info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State:
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp: 240929 15:32:26
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set: 28093c86-5631-11ef-87f4-00163eab83df:3
Executed_Gtid_Set: 28093c86-5631-11ef-87f4-00163eab83df:1-2,
cea38b81-6b2a-11ef-926f-00163e8c8b06:1-3
Auto_Position: 0
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
Master_public_key_path:
Get_master_public_key: 0
Network_Namespace:
1 row in set, 1 warning (0.00 sec)
greatsql> SELECT * FROM PERFORMANCE_SCHEMA.REPLICATION_APPLIER_STATUS_BY_WORKER LIMIT 1\G
*************************** 1. row ***************************
CHANNEL_NAME:
WORKER_ID: 1
THREAD_ID: NULL
SERVICE_STATE: OFF
LAST_ERROR_NUMBER: 13146
LAST_ERROR_MESSAGE: Worker 1 failed executing transaction '28093c86-5631-11ef-87f4-00163eab83df:3' at master log binlog.000001, end_log_pos 2182; Column 1 of table 'test01.smbms_address' cannot be converted from type 'varchar(45(bytes))' to type 'varchar(60(bytes) utf8mb4)'
LAST_ERROR_TIMESTAMP: 2024-09-29 15:32:26.598104
通过performance_schema.replication_applier_status_by_worker
表的详细错误信息可知,从库回放时出现数据类型转换问题,导致同步报错。涉及的表是test01.smbms_address
,主库该列定义为varchar(45 bytes),从库同一列定义为varchar(60 bytes) utf8mb4,数据类型不匹配。
2.11 对比表结构
© 版权声明
文章版权归作者所有,未经允许请勿转载。
相关文章
暂无评论...