找回密码
 立即注册
首页 业界区 安全 GreatSQL从库报错13146:字符集不一致问题处理 ...

GreatSQL从库报错13146:字符集不一致问题处理

方方仪 2025-6-18 09:01:46
GreatSQL从库报错13146:字符集不一致问题处理

1.问题概述

需要将数据反向同步到源端,在使用 SELECT INTO OUTFILE 和 LOAD DATA 的方式进行数据恢复后配置同步,从库发生报错13146数据类型转换失败,导致同步异常;通过对比表结构和列的字符集,发现主从库相关表、列字符集设置不一致,修改为一致后,同步正常
2.问题复现

本次测试基于 GreatSQL 8.0.32
2.1 初始化2个单机实例


2.2 主库创建测试表
  1. greatsql> CREATE TABLE `smbms_address` (
  2. `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  3.   `contact` varchar(15) DEFAULT NULL COMMENT '联系人姓名',
  4.   `addressDesc` varchar(50) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL COMMENT '收货地址明细',
  5.   `postCode` varchar(15) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL COMMENT '邮编',
  6.   `tel` varchar(20) DEFAULT NULL COMMENT '联系人电话',
  7.   `createdBy` bigint DEFAULT NULL COMMENT '创建者',
  8.   `creationDate` datetime DEFAULT NULL COMMENT '创建时间',
  9.   `modifyBy` bigint DEFAULT NULL COMMENT '修改者',
  10.   `modifyDate` datetime DEFAULT NULL COMMENT '修改时间',
  11.   `userId` bigint DEFAULT NULL COMMENT '用户ID',
  12.   PRIMARY KEY (`id`));
  13.   
  14. greatsql> INSERT INTO `smbms_address`(`id`,`contact`,`addressDesc`,`postCode`,`tel`,`createdBy`,`creationDate`,
  15. `modifyBy`,`modifyDate`,`userId`) values
  16. (1,'小丽','北京市','100010','13689999',1,'2016-04-13 10:09:00',NULL,NULL,201),
  17. (2,'小张','北京市','100000','185672312',1,'2016-04-13 01:10:32',NULL,NULL,201);
复制代码
2.3 查看数据
  1. greatsql> SELECT * FROM smbms_address;
  2. +----+---------+-------------+----------+-----------+-----------+---------------------+----------+------------+--------+
  3. | id | contact | addressDesc | postCode | tel       | createdBy | creationDate        | modifyBy | modifyDate | userId |
  4. +----+---------+-------------+----------+-----------+-----------+---------------------+----------+------------+--------+
  5. |  1 | 小丽    | 北京市       | 100010   | 13689999  |         1 | 2016-04-13 10:09:00 |     NULL | NULL       |    201 |
  6. |  2 | 小张    | 北京市       | 100000   | 185672312 |         1 | 2016-04-13 01:10:32 |     NULL | NULL       |    201 |
  7. +----+---------+-------------+----------+-----------+-----------+---------------------+----------+------------+--------+
  8. 2 rows in set (0.00 sec)
复制代码
2.4 主库导出数据
  1. greatsql> SELECT * FROM test01.smbms_address INTO OUTFILE '/data/smbms_address.txt' FIELDS TERMINATED BY '_~'  ENCLOSED BY '"';
复制代码
2.5 从库创建表
  1. greatsql> CREATE TABLE `smbms_address` (
  2.   `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  3.   `contact` varchar(15) DEFAULT NULL COMMENT '联系人姓名',
  4.   `addressDesc` varchar(50) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL COMMENT '收货地址明细',
  5.   `postCode` varchar(15) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL COMMENT '邮编',
  6.   `tel` varchar(20) DEFAULT NULL COMMENT '联系人电话',
  7.   `createdBy` bigint DEFAULT NULL COMMENT '创建者',
  8.   `creationDate` datetime DEFAULT NULL COMMENT '创建时间',
  9.   `modifyBy` bigint DEFAULT NULL COMMENT '修改者',
  10.   `modifyDate` datetime DEFAULT NULL COMMENT '修改时间',
  11.   `userId` bigint DEFAULT NULL COMMENT '用户ID',
  12.   PRIMARY KEY (`id`));
复制代码
2.6 从库导入数据
  1. greatsql> LOAD DATA INFILE '/data/smbms_address.txt' INTO TABLE test01.smbms_address FIELDS TERMINATED BY '_~'  ENCLOSED BY '"';
复制代码
2.7 从库查询数据
  1. greatsql> SELECT * FROM smbms_address;
  2. +----+---------+-------------+----------+-----------+-----------+---------------------+----------+------------+--------+
  3. | id | contact | addressDesc | postCode | tel       | createdBy | creationDate        | modifyBy | modifyDate | userId |
  4. +----+---------+-------------+----------+-----------+-----------+---------------------+----------+------------+--------+
  5. |  1 | 小丽    | 北京市      | 100010   | 13689999  |         1 | 2016-04-13 10:09:00 |     NULL | NULL       |    201 |
  6. |  2 | 小张    | 北京市      | 100000   | 185672312 |         1 | 2016-04-13 01:10:32 |     NULL | NULL       |    201 |
  7. +----+---------+-------------+----------+-----------+-----------+---------------------+----------+------------+--------+
  8. 2 rows in set (0.00 sec)
复制代码
2.8 从库建立复制
  1. #主库查看当前gtid和pos位点信息
  2. greatsql> SHOW MASTER STATUS;
  3. +---------------+----------+--------------+------------------+------------------------------------------+
  4. | File          | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set                        |
  5. +---------------+----------+--------------+------------------+------------------------------------------+
  6. | binlog.000001 |     1693 |              |                  | 28093c86-5631-11ef-87f4-00163eab83df:1-2 |
  7. +---------------+----------+--------------+------------------+------------------------------------------+
  8. 1 row in set (0.00 sec)
  9. #从库执行
  10. greatsql> RESET MASTER;
  11. Query OK, 0 rows affected (0.04 sec)
  12. greatsql>RESET SLAVE ALL;
  13. Query OK, 0 rows affected, 1 warning (0.03 sec)
  14. greatsql> SET GLOBAL GTID_PURGED='28093c86-5631-11ef-87f4-00163eab83df:1-2';
  15. Query OK, 0 rows affected (0.00 sec)
  16. 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;
  17. Query OK, 0 rows affected, 8 warnings (0.05 sec)
  18. greatsql> START SLAVE;
  19. Query OK, 0 rows affected, 1 warning (0.04 sec)
  20. greatsql> SHOW SLAVE STATUS \G
  21. *************************** 1. row ***************************
  22.                Slave_IO_State: Waiting for source to send event
  23.                   Master_Host: 172.17.140.13
  24.                   Master_User: replabc
  25.                   Master_Port: 5506
  26.                 Connect_Retry: 60
  27.               Master_Log_File: binlog.000001
  28.           Read_Master_Log_Pos: 1693
  29.                Relay_Log_File: gip-relay-bin.000002
  30.                 Relay_Log_Pos: 323
  31.         Relay_Master_Log_File: binlog.000001
  32.              Slave_IO_Running: Yes
  33.             Slave_SQL_Running: Yes
  34.               Replicate_Do_DB:
  35.           Replicate_Ignore_DB:
  36.            Replicate_Do_Table:
  37.        Replicate_Ignore_Table:
  38.       Replicate_Wild_Do_Table:
  39.   Replicate_Wild_Ignore_Table:
  40.                    Last_Errno: 0
  41.                    Last_Error:
  42.                  Skip_Counter: 0
  43.           Exec_Master_Log_Pos: 1693
  44.               Relay_Log_Space: 531
  45.               Until_Condition: None
  46.                Until_Log_File:
  47.                 Until_Log_Pos: 0
  48.            Master_SSL_Allowed: No
  49.            Master_SSL_CA_File:
  50.            Master_SSL_CA_Path:
  51.               Master_SSL_Cert:
  52.             Master_SSL_Cipher:
  53.                Master_SSL_Key:
  54.         Seconds_Behind_Master: 0
  55. Master_SSL_Verify_Server_Cert: No
  56.                 Last_IO_Errno: 0
  57.                 Last_IO_Error:
  58.                Last_SQL_Errno: 0
  59.                Last_SQL_Error:
  60.   Replicate_Ignore_Server_Ids:
  61.              Master_Server_Id: 135506
  62.                   Master_UUID: 28093c86-5631-11ef-87f4-00163eab83df
  63.              Master_Info_File: mysql.slave_master_info
  64.                     SQL_Delay: 0
  65.           SQL_Remaining_Delay: NULL
  66.       Slave_SQL_Running_State: Replica has read all relay log; waiting for more updates
  67.            Master_Retry_Count: 86400
  68.                   Master_Bind:
  69.       Last_IO_Error_Timestamp:
  70.      Last_SQL_Error_Timestamp:
  71.                Master_SSL_Crl:
  72.            Master_SSL_Crlpath:
  73.            Retrieved_Gtid_Set:
  74.             Executed_Gtid_Set: 28093c86-5631-11ef-87f4-00163eab83df:1-2,
  75. cea38b81-6b2a-11ef-926f-00163e8c8b06:1-2
  76.                 Auto_Position: 0
  77.          Replicate_Rewrite_DB:
  78.                  Channel_Name:
  79.            Master_TLS_Version:
  80.        Master_public_key_path:
  81.         Get_master_public_key: 0
  82.             Network_Namespace:
  83. 1 row in set, 1 warning (0.01 sec)
复制代码
2.9 主库插入新数据
  1. greatsql> INSERT INTO smbms_address values(3,'小小','北京市','100021','133876742',1,'2016-04-13 00:00:05',NULL,NULL,201);
复制代码
2.10 从库查看复制状态
  1. greatsql> SHOW SLAVE STATUS \G
  2. *************************** 1. row ***************************
  3.                Slave_IO_State: Waiting for source to send event
  4.                   Master_Host: 172.17.140.13
  5.                   Master_User: replabc
  6.                   Master_Port: 5506
  7.                 Connect_Retry: 60
  8.               Master_Log_File: binlog.000001
  9.           Read_Master_Log_Pos: 2213
  10.                Relay_Log_File: gip-relay-bin.000002
  11.                 Relay_Log_Pos: 323
  12.         Relay_Master_Log_File: binlog.000001
  13.              Slave_IO_Running: Yes
  14.             Slave_SQL_Running: No
  15.               Replicate_Do_DB:
  16.           Replicate_Ignore_DB:
  17.            Replicate_Do_Table:
  18.        Replicate_Ignore_Table:
  19.       Replicate_Wild_Do_Table:
  20.   Replicate_Wild_Ignore_Table:
  21.                    Last_Errno: 13146
  22.                    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.
  23.                  Skip_Counter: 0
  24.           Exec_Master_Log_Pos: 1693
  25.               Relay_Log_Space: 1051
  26.               Until_Condition: None
  27.                Until_Log_File:
  28.                 Until_Log_Pos: 0
  29.            Master_SSL_Allowed: No
  30.            Master_SSL_CA_File:
  31.            Master_SSL_CA_Path:
  32.               Master_SSL_Cert:
  33.             Master_SSL_Cipher:
  34.                Master_SSL_Key:
  35.         Seconds_Behind_Master: NULL
  36. Master_SSL_Verify_Server_Cert: No
  37.                 Last_IO_Errno: 0
  38.                 Last_IO_Error:
  39.                Last_SQL_Errno: 13146
  40.                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.
  41.   Replicate_Ignore_Server_Ids:
  42.              Master_Server_Id: 135506
  43.                   Master_UUID: 28093c86-5631-11ef-87f4-00163eab83df
  44.              Master_Info_File: mysql.slave_master_info
  45.                     SQL_Delay: 0
  46.           SQL_Remaining_Delay: NULL
  47.       Slave_SQL_Running_State:
  48.            Master_Retry_Count: 86400
  49.                   Master_Bind:
  50.       Last_IO_Error_Timestamp:
  51.      Last_SQL_Error_Timestamp: 240929 15:32:26
  52.                Master_SSL_Crl:
  53.            Master_SSL_Crlpath:
  54.            Retrieved_Gtid_Set: 28093c86-5631-11ef-87f4-00163eab83df:3
  55.             Executed_Gtid_Set: 28093c86-5631-11ef-87f4-00163eab83df:1-2,
  56. cea38b81-6b2a-11ef-926f-00163e8c8b06:1-3
  57.                 Auto_Position: 0
  58.          Replicate_Rewrite_DB:
  59.                  Channel_Name:
  60.            Master_TLS_Version:
  61.        Master_public_key_path:
  62.         Get_master_public_key: 0
  63.             Network_Namespace:
  64. 1 row in set, 1 warning (0.00 sec)
  65. greatsql> SELECT * FROM PERFORMANCE_SCHEMA.REPLICATION_APPLIER_STATUS_BY_WORKER LIMIT 1\G
  66. *************************** 1. row ***************************
  67.            CHANNEL_NAME:
  68.               WORKER_ID: 1
  69.               THREAD_ID: NULL
  70.           SERVICE_STATE: OFF
  71.       LAST_ERROR_NUMBER: 13146
  72.      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)'
  73.    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 对比表结构

主库查看:
  1. greatsql> SHOW CREATE TABLE smbms_address \G
  2. *************************** 1. row ***************************
  3.        Table: smbms_address
  4. Create Table: CREATE TABLE `smbms_address` (
  5.   `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  6.   `contact` varchar(15) DEFAULT NULL COMMENT '联系人姓名',
  7.   `addressDesc` varchar(50) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL COMMENT '收货地址明细',
  8.   `postCode` varchar(15) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL COMMENT '邮编',
  9.   `tel` varchar(20) DEFAULT NULL COMMENT '联系人电话',
  10.   `createdBy` bigint DEFAULT NULL COMMENT '创建者',
  11.   `creationDate` datetime DEFAULT NULL COMMENT '创建时间',
  12.   `modifyBy` bigint DEFAULT NULL COMMENT '修改者',
  13.   `modifyDate` datetime DEFAULT NULL COMMENT '修改时间',
  14.   `userId` bigint DEFAULT NULL COMMENT '用户ID',
  15.   PRIMARY KEY (`id`)
  16. ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb3
  17. 1 row in set (0.00 sec)
复制代码
从库查看:
  1. greatsql> SHOW CREATE TABLE smbms_address \G
  2. *************************** 1. row ***************************
  3.        Table: smbms_address
  4. Create Table: CREATE TABLE `smbms_address` (
  5.   `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  6.   `contact` varchar(15) DEFAULT NULL COMMENT '联系人姓名',
  7.   `addressDesc` varchar(50) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL COMMENT '收货地址明细',
  8.   `postCode` varchar(15) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL COMMENT '邮编',
  9.   `tel` varchar(20) DEFAULT NULL COMMENT '联系人电话',
  10.   `createdBy` bigint DEFAULT NULL COMMENT '创建者',
  11.   `creationDate` datetime DEFAULT NULL COMMENT '创建时间',
  12.   `modifyBy` bigint DEFAULT NULL COMMENT '修改者',
  13.   `modifyDate` datetime DEFAULT NULL COMMENT '修改时间',
  14.   `userId` bigint DEFAULT NULL COMMENT '用户ID',
  15.   PRIMARY KEY (`id`)
  16. ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
  17. 1 row in set (0.00 sec)
复制代码
可以看到上述 smbms_address表的字符集两边不一致,主库为utf8mb3,从库为utf8mb4,那么所属列的字符集是否一致呢?
2.12 确认表字段相关字符集和排序规则

主库查看:
  1. greatsql> SELECT table_schema,table_name,column_name,character_set_name,COLLATION_NAME,COLUMN_TYPE from information_schema.columns where table_schema = 'test01' and table_name = 'smbms_address';
  2. +--------------+---------------+--------------+--------------------+--------------------+-------------+
  3. | TABLE_SCHEMA | TABLE_NAME    | COLUMN_NAME  | CHARACTER_SET_NAME | COLLATION_NAME     | COLUMN_TYPE |
  4. +--------------+---------------+--------------+--------------------+--------------------+-------------+
  5. | test01       | smbms_address | addressDesc  | utf8mb3            | utf8mb3_general_ci | varchar(50) |
  6. | test01       | smbms_address | contact      | utf8mb3            | utf8mb3_general_ci | varchar(15) |
  7. | test01       | smbms_address | createdBy    | NULL               | NULL               | bigint      |
  8. | test01       | smbms_address | creationDate | NULL               | NULL               | datetime    |
  9. | test01       | smbms_address | id           | NULL               | NULL               | bigint      |
  10. | test01       | smbms_address | modifyBy     | NULL               | NULL               | bigint      |
  11. | test01       | smbms_address | modifyDate   | NULL               | NULL               | datetime    |
  12. | test01       | smbms_address | postCode     | utf8mb3            | utf8mb3_general_ci | varchar(15) |
  13. | test01       | smbms_address | tel          | utf8mb3            | utf8mb3_general_ci | varchar(20) |
  14. | test01       | smbms_address | userId       | NULL               | NULL               | bigint      |
  15. +--------------+---------------+--------------+--------------------+--------------------+-------------+
  16. 10 rows in set (0.01 sec)
复制代码
从库查看:
  1. greatsql> SELECT table_schema,table_name,column_name,character_set_name,COLLATION_NAME,COLUMN_TYPE from information_schema.columns where table_schema = 'test01' and table_name = 'smbms_address';
  2. +--------------+---------------+--------------+--------------------+--------------------+-------------+
  3. | TABLE_SCHEMA | TABLE_NAME    | COLUMN_NAME  | CHARACTER_SET_NAME | COLLATION_NAME     | COLUMN_TYPE |
  4. +--------------+---------------+--------------+--------------------+--------------------+-------------+
  5. | test01       | smbms_address | addressDesc  | utf8mb3            | utf8mb3_general_ci | varchar(50) |
  6. | test01       | smbms_address | contact      | utf8mb4            | utf8mb4_0900_ai_ci | varchar(15) |
  7. | test01       | smbms_address | createdBy    | NULL               | NULL               | bigint      |
  8. | test01       | smbms_address | creationDate | NULL               | NULL               | datetime    |
  9. | test01       | smbms_address | id           | NULL               | NULL               | bigint      |
  10. | test01       | smbms_address | modifyBy     | NULL               | NULL               | bigint      |
  11. | test01       | smbms_address | modifyDate   | NULL               | NULL               | datetime    |
  12. | test01       | smbms_address | postCode     | utf8mb3            | utf8mb3_general_ci | varchar(15) |
  13. | test01       | smbms_address | tel          | utf8mb4            | utf8mb4_0900_ai_ci | varchar(20) |
  14. | test01       | smbms_address | userId       | NULL               | NULL               | bigint      |
  15. +--------------+---------------+--------------+--------------------+--------------------+-------------+
  16. 10 rows in set (0.01 sec)
复制代码
根据 information_schema.columns表中相关信息,可以看到contact列、tel列的字符集都为utf8mb4,排序规则为默认的 utf8mb4_0900_ai_ci;为什么建表时没有指定列所使用的字符集,但还是使用了表的字符集和排序规则?
MySQL手册介绍
通过以下方式选择列的字符集和排序规则:
1.png


  • 如果建表时指定了列的字符集和排序规则,则使用指定的字符集和排序规则;
  • 为列指定了字符集,但没有指定排序规则,则使用该字符集默认的排序规则,可使用show character set语句或查询character sets表;
  • 为列指定了排序规则,但没有指定字符集。列具有排序规则,字符集则是与排序规则相关联的字符集;
  • 没有为列指定字符集或排序规则,因此使用表的默认字符集和排序规则。
这段描述可以解释为什么在创建表时,如果没有明确指定列的字符集,则会使用该表或数据库的默认字符集。这意味着,如果为VARCHAR类型的列没有指定字符集,它将继承表或数据库层面定义的字符集。
2.13 修复从库

采用重建表结构恢复数据后再重新配置同步的方式
1.关闭复制同步
  1. greatsql> STOP SLAVE;
  2. Query OK, 0 rows affected, 1 warning (0.03 sec)
复制代码
2.删除表,并新建表
  1. greatsql> DROP TABLE `smbms_address`;
  2. Query OK, 0 rows affected, 1 warning (0.03 sec)
  3. greatsql> CREATE TABLE `smbms_address` (
  4.   `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  5.   `contact` varchar(15) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL COMMENT '联系人姓名',
  6.   `addressDesc` varchar(50) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL COMMENT '收货地址明细',
  7.   `postCode` varchar(15) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL COMMENT '邮编',
  8.   `tel` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL COMMENT '联系人电话',
  9.   `createdBy` bigint DEFAULT NULL COMMENT '创建者',
  10.   `creationDate` datetime DEFAULT NULL COMMENT '创建时间',
  11.   `modifyBy` bigint DEFAULT NULL COMMENT '修改者',
  12.   `modifyDate` datetime DEFAULT NULL COMMENT '修改时间',
  13.   `userId` bigint DEFAULT NULL COMMENT '用户ID',
  14.   PRIMARY KEY (`id`)
  15. ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb3;
复制代码
3.重新导入数据
  1. greatsql> LOAD DATA INFILE '/data/smbms_address.txt' INTO TABLE test01.smbms_address FIELDS TERMINATED BY '_~'  ENCLOSED BY '"';
复制代码
4.设置gtid,配置同步
  1. greatsql> SHOW MASTER STATUS;
  2. +---------------+----------+--------------+------------------+------------------------------------------+
  3. | File          | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set                        |
  4. +---------------+----------+--------------+------------------+------------------------------------------+
  5. | binlog.000001 |     1693 |              |                  | 28093c86-5631-11ef-87f4-00163eab83df:1-2 |
  6. +---------------+----------+--------------+------------------+------------------------------------------+
  7. 1 row in set (0.00 sec)
  8. greatsql> RESET MASTER;
  9. greatsql> RESET SLAVE;     
  10. greatsql> SET GLOBAL GTID_PURGED='28093c86-5631-11ef-87f4-00163eab83df:1-2';
  11. 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;
  12. Query OK, 0 rows affected, 8 warnings (0.05 sec)
复制代码
5.启动同步
  1. greatsql> START SLAVE;
  2. greatsql> SHOW SLAVE STATUS \G
  3. *************************** 1. row ***************************
  4.                Slave_IO_State: Waiting for source to send event
  5.                   Master_Host: 172.17.140.13
  6.                   Master_User: replabc
  7.                   Master_Port: 5506
  8.                 Connect_Retry: 60
  9.               Master_Log_File: binlog.000001
  10.           Read_Master_Log_Pos: 8659
  11.                Relay_Log_File: gip-relay-bin.000005
  12.                 Relay_Log_Pos: 3721
  13.         Relay_Master_Log_File: binlog.000001
  14.              Slave_IO_Running: Yes
  15.             Slave_SQL_Running: Yes
  16. ......
  17. 1 row in set, 1 warning (0.01 sec)
复制代码
3.总结


  • 在主从复制中,必须保证主库和从库的表结构属性相一致,若表或列的字符集设置不一致,则会抛出异常,导致同步中断。这也是本次同步报错的原因。
  • 若对字符串类型的列存储的数据有特殊要求时,可显示的为列指定字符集。

Enjoy GreatSQL
来源:程序园用户自行投稿发布,如果侵权,请联系站长删除
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!
您需要登录后才可以回帖 登录 | 立即注册