专栏首页张戈的专栏MySQL主从报错解决:Table ‘mysql.gtid_slave_pos’ doesn’t exist

MySQL主从报错解决:Table ‘mysql.gtid_slave_pos’ doesn’t exist

给内部一个数据库做异地热备,热备部分采用了 MariaDB 的 galera 集群模式。然后挑选其中一台作为 Slave 和深圳主集群做主从同步。

主集群是老环境,用的版本还是是 MySQL 5.5.13。用常规办法创建主从同步

MariaDB [(none)]>change master to master_host='192.168.1.100',master_user='rpl',master_password='rpl@201809',master_log_file='mysql-bin.001091',MASTER_LOG_POS=137962110,master_connect_retry=30;
MariaDB [(none)]>start slave;

结果有如下报错:

MariaDB [(none)]> show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.1.100
                  Master_User: rpl
                  Master_Port: 3306
                Connect_Retry: 30
              Master_Log_File: mysql-bin.001093
          Read_Master_Log_Pos: 77139171
               Relay_Log_File: udb158-relay-bin.000002
                Relay_Log_Pos: 237764027
        Relay_Master_Log_File: mysql-bin.001091
             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: 1146
                   Last_Error: Unable to load replication GTID slave state from mysql.gtid_slave_pos: Table 'mysql.gtid_slave_pos' doesn't exist
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 375725743
              Relay_Log_Space: 2086663884
              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: 105914
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error: 
               Last_SQL_Errno: 1146
               Last_SQL_Error: Unable to load replication GTID slave state from mysql.gtid_slave_pos: Table 'mysql.gtid_slave_pos' doesn't exist
  Replicate_Ignore_Server_Ids: 
             Master_Server_Id: 15410
               Master_SSL_Crl: 
           Master_SSL_Crlpath: 
                   Using_Gtid: No
                  Gtid_IO_Pos: 
1 row in set (0.00 sec)

错误信息为:Last_SQL_Error: Unable to load replication GTID slave state from mysql.gtid_slave_pos: Table 'mysql.gtid_slave_pos' doesn't exist

搜了下资料,大部分说是没有执行 mysql_upgrade 导致的,不过我们这边的 MariaDB 是 Docker 跑的,而且用了很长时间了,理论上应该是没问题的才对。

既然提示没有这个表:Table 'mysql.gtid_slave_pos' doesn't exist,那我就创建一个吧!

从网上找到这个建表语句:

CREATE TABLE `gtid_slave_pos` (
       `domain_id` int(10) unsigned NOT NULL,
       `sub_id` bigint(20) unsigned NOT NULL,
       `server_id` int(10) unsigned NOT NULL,
       `seq_no` bigint(20) unsigned NOT NULL,
       PRIMARY KEY (`domain_id`,`sub_id`)
     ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='Replication slave GTID state';

在作为 Slave 的 MariaDB 上执行,然后重启 slave 后问题解决,过程如下:

MariaDB [(none)]> show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.1.100
                  Master_User: rpl
                  Master_Port: 3306
                Connect_Retry: 30
              Master_Log_File: mysql-bin.001093
          Read_Master_Log_Pos: 77139171
               Relay_Log_File: udb158-relay-bin.000002
                Relay_Log_Pos: 237764027
        Relay_Master_Log_File: mysql-bin.001091
             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: 1146
                   Last_Error: Unable to load replication GTID slave state from mysql.gtid_slave_pos: Table 'mysql.gtid_slave_pos' doesn't exist
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 375725743
              Relay_Log_Space: 2086663884
              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: 105914
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error: 
               Last_SQL_Errno: 1146
               Last_SQL_Error: Unable to load replication GTID slave state from mysql.gtid_slave_pos: Table 'mysql.gtid_slave_pos' doesn't exist
  Replicate_Ignore_Server_Ids: 
             Master_Server_Id: 15410
               Master_SSL_Crl: 
           Master_SSL_Crlpath: 
                   Using_Gtid: No
                  Gtid_IO_Pos: 
1 row in set (0.00 sec)
 
MariaDB [(none)]> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
 
Database changed
MariaDB [mysql]> CREATE TABLE `gtid_slave_pos` (
    ->        `domain_id` int(10) unsigned NOT NULL,
    ->        `sub_id` bigint(20) unsigned NOT NULL,
    ->        `server_id` int(10) unsigned NOT NULL,
    ->        `seq_no` bigint(20) unsigned NOT NULL,
    ->        PRIMARY KEY (`domain_id`,`sub_id`)
    ->      ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='Replication slave GTID state';
Query OK, 0 rows affected (0.01 sec)
 
MariaDB [mysql]> stop slave;
Query OK, 0 rows affected (0.04 sec)
 
MariaDB [mysql]> start slave;
Query OK, 0 rows affected (0.00 sec)
 
MariaDB [mysql]> show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Queueing master event to the relay log
                  Master_Host: 192.168.1.100
                  Master_User: rpl
                  Master_Port: 3306
                Connect_Retry: 30
              Master_Log_File: mysql-bin.001093
          Read_Master_Log_Pos: 1059879280
               Relay_Log_File: udb158-relay-bin.000002
                Relay_Log_Pos: 390833600
        Relay_Master_Log_File: mysql-bin.001091
             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: 528795316
              Relay_Log_Space: 3069404437
              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: 101616
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: 15410
               Master_SSL_Crl: 
           Master_SSL_Crlpath: 
                   Using_Gtid: No
                  Gtid_IO_Pos: 
1 row in set (0.00 sec)
 
MariaDB [mysql]>

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

我来说两句

0 条评论
登录 后参与评论

相关文章

  • Linux+Nginx/Apache/Tomcat新增SSL证书,开启https访问教程

    上上篇文章《nginx 平滑升级&新增模块》提到了公司的 https 访问需求。当我新增了 SSL 模块之后,却发现以前还真没部署过 https 访问。 下面整...

    张戈
  • WordPress获取文章浏览总数

    大部分 WordPress 都会安装 wp-postviews 插件来记录文章浏览量,这是一个很实用的插件。不过它并没有提供计算文章浏览总数的功能,为了弥补这个...

    张戈
  • Nginx-helper纯代码版,文章评论发布自动清理Fastcgi缓存

    摘 要 张戈博客之前分享过Nginx开启fastcgi静态缓存加速的教程,文中也提到了WordPress对应的最佳配套插件:Nginx-Helper。本文分享...

    张戈
  • 使用replicate-rewrite-db 实现复制映射 + Replicate_Wild_Do_Table实现复制过滤

    业务方有个需求,需要将node1上的employees库的departments 、dept_manager 这2张表同步到 node2 的 hellodb 库...

    二狗不要跑
  • 3分钟解决MySQL 1062 主从错误

    1062错误----主键冲突,出现这种情况就是从库出现插入操作,主库又重新来了一遍,iothread没问题,sqlthread出错

    py3study
  • show slave status 详解 【MySQL5.7】

    其值是通过将服务器当前的时间戳与二进制日志中的事件的时间戳相对比得到的【MySQL手册上说的是从库SQL线程与IO线程所处理的最近的日志事件的时间戳差】。

    二狗不要跑
  • RocketMQ详解(3)——RocketMQ集群模型与搭建

    RocketMQ天然支持分布式集群模型,其中主节点可读可写,从节点只可读,不可写,类似MySQL的主从模式。RocketMQ主要支持以下几种集群模型:

    张申傲
  • 案例:推进GTID解决MySQL主主不同步问题

    之前文章介绍过MySQL修改lower_case_table_names参数,如果之前大写存储的表将无法识别,需要特殊处理。 最近遇到一例应用开发人员在修改这...

    Alfred Zhao
  • MySQL 的一次错误处理 Got fatal error 1236 from master when reading data from binary log

    mysql 5.5.28-log> show slave status\G *************************** 1. row ******...

    拓荒者
  • mysql 复制

    MySQL的复制功能是构建基于MySQL的大规模、高性能应用的基础。复制功能不仅有利于构建高性能的应用,同时也是高可用性、可扩展性、灾难恢复、备份以及数据仓库等...

    魔王卷子

扫码关注云+社区

领取腾讯云代金券