前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >MySQL主从报错解决:Table ‘mysql.gtid_slave_pos’ doesn’t exist

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

作者头像
张戈
发布2018-10-10 10:23:17
4.3K0
发布2018-10-10 10:23:17
举报
文章被收录于专栏:张戈的专栏

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

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

代码语言:javascript
复制
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;

结果有如下报错:

代码语言:javascript
复制
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,那我就创建一个吧!

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

代码语言:javascript
复制
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 后问题解决,过程如下:

代码语言:javascript
复制
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]>
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2018年09月20日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
云数据库 MariaDB
腾讯云数据库 MariaDB(TencentDB for MariaDB) 让您轻松在云端部署、使用 MariaDB 数据库。MariaDB 是在 MySQL 版权被 Oracle 收购后,由 MySQL 创始人 Monty 创立,其版权授予了“MariaDB基金会(非营利性组织)”以保证 MariaDB 永远开源,良好的开源策略,是企业级应用的最优选择,主流开源社区系统/软件的数据库系统,均已默认配置 MariaDB。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档