首页 > 数据库 >mysql GTID模式跳过错误GTID事务的正确方法

mysql GTID模式跳过错误GTID事务的正确方法

时间:2023-06-11 13:03:46浏览次数:52  
标签:00 TRANSACTION LAST Log SSL Master mysql 跳过 GTID

    最近遇到一个Mysql由于create table时由于从库表表空间问题,从库sql重放进程执行sql失败,导致从库的sql应用进程挂掉。客户反馈,可以跳过失败的create table事务,本博文展示mysql 基于GITD模式跳过错误CTID事务的正确方法。

    1.0 明确错误原因

root@mysqldb 15:53:  [(none)]> show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.56.2
                  Master_User: repl
                  Master_Port: 9506
                Connect_Retry: 60
              Master_Log_File: mybinlog.006091
          Read_Master_Log_Pos: 768927745
               Relay_Log_File: TEST-DB-2-relay-bin.009546
                Relay_Log_Pos: 543586669
        Relay_Master_Log_File: mybinlog.006090
             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: 1813
                   Last_Error: Error 'Tablespace '`test`.`p_gov_......_temp`' exists.' on query. Default database: 'test'. Query: 'CREATE TABLE `p_gov_......_temp` (
 ......
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 543586536
              Relay_Log_Space: 10836318250
              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: 1813
               Last_SQL_Error: Error 'Tablespace '`test`.`p_gov_......_temp`' exists.' on query. Default database: 'test'. Query: 'CREATE TABLE `p_gov_......_temp` (
......
             Replicate_Ignore_Server_Ids: 
             Master_Server_Id: 9506002
                  Master_UUID: 4efcbd9f-c1e2-11eb-b710-0050569e2112
             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: 230607 15:40:49
               Master_SSL_Crl: 
           Master_SSL_Crlpath: 
           Retrieved_Gtid_Set: 4efcbd9f-c1e2-11eb-b710-0050569e2112:1217191452-1442042781
            Executed_Gtid_Set: 24fce019-edde-11ec-8f9e-0050569e562f:1-26407,
4efcbd9f-c1e2-11eb-b710-0050569e2112:1-1441877106:1441877108-1441877109,
54c6f166-c1e4-11eb-b023-0050569e562f:1
                Auto_Position: 1
         Replicate_Rewrite_DB: 
                 Channel_Name: 
           Master_TLS_Version: 
       Master_public_key_path: 
        Get_master_public_key: 0
            Network_Namespace: 
1 row in set (0.00 sec)

root@mysqldb 15:53:  [(none)]> 

    通过观察show slave status可以看到从库192.168.56.2的Slave_Sql由于1813错误,具体原因是表空间问题导致create table失败,引起从库Slave_Sql进程挂起。

    2.0 问题处理方法

    经过沟通,允许跳过失败的GTID事务。至于如何跳过GITD事务,网上有很多资料,有的从show slave status输出结果中跳过Retrieved_Gtid_Set,有的是Executed_Gtid_Set拼凑的,可以说均是错误的。另外,有些说从binlog里边挖,其实没有那么麻烦,要跳过失败事务的GTID可以通过sql直接查询到。

root@mysqldb 16:20:  [(none)]> select * from performance_schema.replication_applier_status_by_worker\G
*************************** 1. row ***************************
                                           CHANNEL_NAME: 
                                              WORKER_ID: 0
                                              THREAD_ID: NULL
                                          SERVICE_STATE: OFF
                                      LAST_ERROR_NUMBER: 1813
                                     LAST_ERROR_MESSAGE: Error 'Tablespace '`test`.`p_gov_......_temp`' exists.' on query. Default database: 'test'. Query: 'CREATE TABLE `p_gov_......_temp` (
 ......
 															 LAST_ERROR_TIMESTAMP: 2023-06-07 16:11:59.433420
                               LAST_APPLIED_TRANSACTION: 
     LAST_APPLIED_TRANSACTION_ORIGINAL_COMMIT_TIMESTAMP: 0000-00-00 00:00:00.000000
    LAST_APPLIED_TRANSACTION_IMMEDIATE_COMMIT_TIMESTAMP: 0000-00-00 00:00:00.000000
         LAST_APPLIED_TRANSACTION_START_APPLY_TIMESTAMP: 0000-00-00 00:00:00.000000
           LAST_APPLIED_TRANSACTION_END_APPLY_TIMESTAMP: 0000-00-00 00:00:00.000000
                                   APPLYING_TRANSACTION: 4efcbd9f-c1e2-11eb-b710-0050569e2112:1441877107 《《《《《《《《《《《要跳过的事务
         APPLYING_TRANSACTION_ORIGINAL_COMMIT_TIMESTAMP: 2023-06-07 14:42:22.913515
        APPLYING_TRANSACTION_IMMEDIATE_COMMIT_TIMESTAMP: 2023-06-07 14:42:22.913515
             APPLYING_TRANSACTION_START_APPLY_TIMESTAMP: 2023-06-07 16:11:59.392908
                 LAST_APPLIED_TRANSACTION_RETRIES_COUNT: 0
   LAST_APPLIED_TRANSACTION_LAST_TRANSIENT_ERROR_NUMBER: 0
  LAST_APPLIED_TRANSACTION_LAST_TRANSIENT_ERROR_MESSAGE: 
LAST_APPLIED_TRANSACTION_LAST_TRANSIENT_ERROR_TIMESTAMP: 0000-00-00 00:00:00.000000
                     APPLYING_TRANSACTION_RETRIES_COUNT: 0
       APPLYING_TRANSACTION_LAST_TRANSIENT_ERROR_NUMBER: 0
      APPLYING_TRANSACTION_LAST_TRANSIENT_ERROR_MESSAGE: 
    APPLYING_TRANSACTION_LAST_TRANSIENT_ERROR_TIMESTAMP: 0000-00-00 00:00:00.000000
1 row in set (0.00 sec)

查询结果中 APPLYING_TRANSACTION: 4efcbd9f-c1e2-11eb-b710-0050569e2112:1441877107 就是要跳过的事务GTID号。

3.0 GTID跳过失败事务执行过程

root@mysqldb 16:31:  [(none)]>  SET GTID_NEXT='4efcbd9f-c1e2-11eb-b710-0050569e2112:1441877107';
Query OK, 0 rows affected (0.00 sec)

root@mysqldb 16:33:  [(none)]> select @@gtid_next;
+-------------------------------------------------+
| @@gtid_next                                     |
+-------------------------------------------------+
| 4efcbd9f-c1e2-11eb-b710-0050569e2112:1441877107 |
+-------------------------------------------------+
1 row in set (0.00 sec)

root@mysqldb 16:33:  [(none)]> BEGIN; COMMIT;
Query OK, 0 rows affected (0.01 sec)

Query OK, 0 rows affected (0.01 sec)

root@mysqldb 16:33:  [(none)]> select @@gtid_next;
+-------------------------------------------------+
| @@gtid_next                                     |
+-------------------------------------------------+
| 4efcbd9f-c1e2-11eb-b710-0050569e2112:1441877107 |
+-------------------------------------------------+
1 row in set (0.00 sec)

root@mysqldb 16:33:  [(none)]> SET SESSION GTID_NEXT = AUTOMATIC;
Query OK, 0 rows affected (0.00 sec)

root@mysqldb 16:34:  [(none)]> select @@gtid_next;
+-------------+
| @@gtid_next |
+-------------+
| AUTOMATIC   |
+-------------+
1 row in set (0.00 sec)

root@mysqldb 16:34:  [(none)]> 
root@mysqldb 16:34:  [(none)]> 
root@mysqldb 16:34:  [(none)]> start slave;
Query OK, 0 rows affected (0.00 sec)

root@mysqldb 16:34:  [(none)]> 

root@mysqldb 16:34:  [(none)]> show slave statuS\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.56.2
                  Master_User: repl
                  Master_Port: 9506
                Connect_Retry: 60
              Master_Log_File: mybinlog.006092
          Read_Master_Log_Pos: 726558126
               Relay_Log_File: TEST-DB-2-relay-bin.009546
                Relay_Log_Pos: 640919944
        Relay_Master_Log_File: mybinlog.006090
             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: 640919811
              Relay_Log_Space: 11867704299
              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: 6329
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: 9506002
                  Master_UUID: 4efcbd9f-c1e2-11eb-b710-0050569e2112
             Master_Info_File: mysql.slave_master_info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Reading event from the relay log
           Master_Retry_Count: 86400
                  Master_Bind: 
      Last_IO_Error_Timestamp: 
     Last_SQL_Error_Timestamp: 
               Master_SSL_Crl: 
           Master_SSL_Crlpath: 
           Retrieved_Gtid_Set: 4efcbd9f-c1e2-11eb-b710-0050569e2112:1217191452-1442167357
            Executed_Gtid_Set: 24fce019-edde-11ec-8f9e-0050569e562f:1-26407,
4efcbd9f-c1e2-11eb-b710-0050569e2112:1-1441891442,
54c6f166-c1e4-11eb-b023-0050569e562f:1
                Auto_Position: 1
         Replicate_Rewrite_DB: 
                 Channel_Name: 
           Master_TLS_Version: 
       Master_public_key_path: 
        Get_master_public_key: 0
            Network_Namespace: 
1 row in set (0.00 sec)

root@mysqldb 16:34:  [(none)]> 



标签:00,TRANSACTION,LAST,Log,SSL,Master,mysql,跳过,GTID
From: https://blog.51cto.com/u_3557740/6457462

相关文章

  • MySQL密码找回
    MySQL忘记密码如何找回以管理员身份打开cmd,关闭服务netstopmysql跳过密码授权登录mysqld--console--skip-grant-tables--shared-memory执行完这个命令后,进程会卡住,为正常情况。以管理员身份另外打开一个cmd进入mysql内置库,修改密码//依次输入以下命令mysqlu......
  • MySQL逻辑备份
    一、mysqldump1.mysqldump的导出--只导出存储过程【dump备份】mysqldump-uroot-p-n-t-d--skip-add-drop-table-R数据库名>文件名##其中,-d表示--no-data(Norowinformation),-n表示--no-create-db不导出建库语句,-t表示--no-create-info不导出建表语句,##......
  • 【已解决】MySQL连接错误 ERROR 1129 (00000): Host ” is blocked because of many c
     问题连接MySQL 报错 ERROR1129(00000):Host”isblockedbecauseofmanyconnectionerrors原因同一个IP在短时间内产生太多终端的数据库连接(超过mysql数据库max_connection_errors设置),导致被阻塞。在系统变量:max_connect_errors设置了允许中断的次数,超过了这个次数(或者......
  • MySQL数据库死锁问题
    参看:https://www.bilibili.com/video/BV1RT4y1R7bL/?spm_id_from=333.337.search-card.all.click&vd_source=46d50b5d646b50dcb2a208d3946b1598https://www.bilibili.com/video/BV1Sm4y1C7WX/?spm_id_from=333.337.search-card.all.click&vd_source=46d50b5d646b50dcb......
  • 基于php的外卖订餐网站(php+mysql)
    介绍一个基于php的外卖订餐网站,包括前端和后台。效果演示http://101.43.124.118:8001/admin源码地址https://github.com/geeeeeeeek/dingfanzu代码说明htaccessRewrite配置文件,需要放入到项目根目录configs.php需要配置数据库连接信息(主机、用户名、密码),系统常量,debug......
  • Mysql文章大汇总,一文全搞定!!!
    一次MySQL千万级大表的优化过程开发人员必备的9大MySQL索引和查询优化mysql性能优化之一【索引--基础】mysql性能优化一mysql性能优化二高级版MySQL优化方案常见mysql的慢查询优化方式MySQL性能优化之骨灰级,高阶神技!史上最全的MySQL高性能优化实战总结!Spring-boot+Mybatis+Maven......
  • mysql 进程初始化killed问题
    问题描述:[root@it01soft]#/mysql/mysql57/bin/mysqld--defaults-file=/etc/my.cnf--user=mysql--initialize-insecure--consoleKilled问题分析:1.查看错误日志,错误日志报错如下:[root@it01soft]#more/mysqldata/mysql_3306/log/mysql-error.log2023-06-09T19:49:59.796928......
  • postgresql/lightdb批量导入导出数据系列copy/ltuldr/ltldr/lt_bulkload及最佳实践推
    文件位于服务器上,这就限制了使用范围。为此,对于导出,lightdb提供了高性能导出版本ltuldr。对于导入,lightdb在23.1之前提供lt_bulkload,见下文;从23.1开始,支持和oraclesql*loader对应的ltldr。copy可用于快速导入和导出数据,主要用途如下:TheCOPYcommandmovesdatabetweenPostg......
  • 深入理解MySQL Binlog:从原理到实践
    binlog介绍记录了所有的DDL和DML(除了数据查询语句)语句,以事件形式记录,还包含语句所执行的消耗的时间,MySQL的二进制日志是事务安全型的。作用:复制:MySQLReplication在Master端开启binlog,Master把它的二进制日志传递给slaves并回放来达到master-slave数据一致的目的数据恢复:......
  • 【技术积累】Mysql中的SQL高级技巧【一】
    什么是多表查询?如何在MySQL中进行多表查询?多表查询就是在一个查询中涉及到多个表,通过特定的关联方式连接多个表,并根据条件从中查询出所需要的数据。多表查询是关系型数据库中最为基础的应用之一。一个比较典型的例子就是,我们在查询一个订单的详细信息时,需要从订单表中获取订单......