51工具盒子

依楼听风雨
笑看云卷云舒,淡观潮起潮落

如何调试MySQL复制错误1049?

英文:

How to debug MySQL replication error 1049?

问题 {#heading}

这是SHOW SLAVE STATUS\G的结果:

*************************** 1. row ***************************
               Slave_IO_State: 等待源发送事件
                  Master_Host: 185.128.xxx.xxx
                  Master_User: replica
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000002
          Read_Master_Log_Pos: 2456753
               Relay_Log_File: mysql-relay-bin.000003
                Relay_Log_Pos: 1595182
        Relay_Master_Log_File: mysql-bin.000002
             Slave_IO_Running: 是
            Slave_SQL_Running: 否
              Replicate_Do_DB:
          Replicate_Ignore_DB:
           Replicate_Do_Table:
       Replicate_Ignore_Table:
      Replicate_Wild_Do_Table:
  Replicate_Wild_Ignore_Table:
                   Last_Errno: 1049
                   Last_Error: 协调器停止,因为工作进程中发生错误。 最近的失败是:Worker 1在源日志mysql-bin.000002执行事务 'ANONYMOUS',结束日志位置1595341。 有关此故障或其他故障的详细信息,请参阅错误日志和/或performance_schema.replication_applier_status_by_worker表。
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 1594966
              Relay_Log_Space: 2457347
              Until_Condition: 无
               Until_Log_File:
                Until_Log_Pos: 0
           Master_SSL_Allowed: 否
           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: 否
                Last_IO_Errno: 0
                Last_IO_Error:
               Last_SQL_Errno: 1049
               Last_SQL_Error: 协调器停止,因为工作进程中发生错误。 最近的失败是:Worker 1在源日志mysql-bin.000002执行事务 'ANONYMOUS',结束日志位置1595341。 有关此故障或其他故障的详细信息,请参阅错误日志和/或performance_schema.replication_applier_status_by_worker表。
  Replicate_Ignore_Server_Ids:
             Master_Server_Id: 1
                  Master_UUID: 42e23b0a-9fec-11ea-a6a6-00163e051c80
             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: 230810 13:58:36
               Master_SSL_Crl:
           Master_SSL_Crlpath:
           Retrieved_Gtid_Set:
            Executed_Gtid_Set:
                Auto_Position: 0
         Replicate_Rewrite_DB:
                 Channel_Name:
           Master_TLS_Version:
       Master_public_key_path:
        Get_master_public_key: 0
            Network_Namespace:
1行记录,1个警告 (0.00秒)

根据一些研究,错误代码1049表示"未知数据库";但是说实话,我不知道如何调试?

我现在应该做什么?我应该执行STOP SLAVE吗?然后再执行START SLAVE?还是如何知道调用了哪个未知数据库?


主服务器的配置:

bind-address = 185.128.xxx.xxx
server-id = 1
log_bin = /var/log/mysql/mysql-bin.log
binlog_do_db = my_db_name

从服务器的配置:

server-id = 2
max_binlog_size = 100M
# log_bin = /var/log/mysql/mysql-bin.log
binlog_do_db = my_db_name
relay-log = /var/log/mysql/mysql-relay-bin.log

英文:

I had a working MySQL master-slave replication that recently I've noticed it's been failed few mins ago.

Here's the result of SHOW SLAVE STATUS\G:

*************************** 1. row ***************************
               Slave_IO_State: Waiting for source to send event
                  Master_Host: 185.128.xxx.xxx
                  Master_User: replica
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000002
          Read_Master_Log_Pos: 2456753
               Relay_Log_File: mysql-relay-bin.000003
                Relay_Log_Pos: 1595182
        Relay_Master_Log_File: mysql-bin.000002
             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: 1049
                   Last_Error: Coordinator stopped because there were error(s) in the worker(s). The most recent failure being: Worker 1 failed executing transaction 'ANONYMOUS' at source log mysql-bin.000002, end_log_pos 1595341. 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: 1594966
              Relay_Log_Space: 2457347
              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: 1049
               Last_SQL_Error: Coordinator stopped because there were error(s) in the worker(s). The most recent failure being: Worker 1 failed executing transaction 'ANONYMOUS' at source log mysql-bin.000002, end_log_pos 1595341. 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: 1
                  Master_UUID: 42e23b0a-9fec-11ea-a6a6-00163e051c80
             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: 230810 13:58:36
               Master_SSL_Crl:
           Master_SSL_Crlpath:
           Retrieved_Gtid_Set:
            Executed_Gtid_Set:
                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)

Based on some research, the error code 1049 means "Unknown Database"; But honestly I have no idea how to debug?

What should I do now? Should I STOP SLAVE? And START SLAVE again? Or how to know which database is called that has been unknown?


Configuration on the Master:

bind-address = 185.128.xxx.xxx
server-id = 1
log_bin = /var/log/mysql/mysql-bin.log
binlog_do_db = my_db_name

Configuration on the Slave:

server-id = 2
max_binlog_size = 100M
# log_bin = /var/log/mysql/mysql-bin.log
binlog_do_db = my_db_name
relay-log = /var/log/mysql/mysql-relay-bin.log

答案1 {#1}

得分: 1

如何知道已知道的数据库是哪个?

至少这很容易:

echo "show databases;" | mysql -h dbhost1 > dbsOnDb1
echo "show databases;" | mysql -h dbhost2 > dbsOnDb2
diff dbsOnDb1 dbsOnDb2

(在Linux/Unix上)

然后只需在从服务器上创建数据库并重新启动从服务器进程。

但您真的应该调查一下为什么CREATE DATABASE语句没有出现在二进制日志中。最近是否更改了--replicate-do-db或--replicate-ignore-db?存在一种奇怪的作用域问题,例如,如果您正在排除名为'local'的数据库,并且执行以下操作:

USE local;
CREATE DATABASE newdb;

那么该语句将不会被复制,因为它在本地数据库中执行(即使其影响超出了该数据库)。 英文:

> how to know which database is called that has been unknown?

That at least is easy:

echo "show databases;" | mysql -h dbhost1 >dbsOnDb1
echo "show databases;" | mysql -h dbhost2 >dbsOnDb2
diff dbsOnDb1 dbsOnDb2

(on Linux/Unix)

Then just create the database on the slave and restart the slave process.

But you really should investigate why the CREATE DATABASE statement was not in the binlog. Have --replicate-do-db or --replicate-ignore-db been chaged recently? There is a weird scoping thing where if (for example) you are excluding the database named 'local' and you do this:

USE local;
CREATE DATABASE newdb;

Then the statement will not be replicated as it was executed in the local database (even though its effect is outside that database).


赞(1)
未经允许不得转载:工具盒子 » 如何调试MySQL复制错误1049?