如何调试MySQL复制错误1049?

huangapple go评论139阅读模式
英文:

How to debug MySQL replication error 1049?

问题

这是SHOW SLAVE STATUS\G的结果:

  1. *************************** 1. row ***************************
  2. Slave_IO_State: 等待源发送事件
  3. Master_Host: 185.128.xxx.xxx
  4. Master_User: replica
  5. Master_Port: 3306
  6. Connect_Retry: 60
  7. Master_Log_File: mysql-bin.000002
  8. Read_Master_Log_Pos: 2456753
  9. Relay_Log_File: mysql-relay-bin.000003
  10. Relay_Log_Pos: 1595182
  11. Relay_Master_Log_File: mysql-bin.000002
  12. Slave_IO_Running:
  13. Slave_SQL_Running:
  14. Replicate_Do_DB:
  15. Replicate_Ignore_DB:
  16. Replicate_Do_Table:
  17. Replicate_Ignore_Table:
  18. Replicate_Wild_Do_Table:
  19. Replicate_Wild_Ignore_Table:
  20. Last_Errno: 1049
  21. Last_Error: 协调器停止,因为工作进程中发生错误。 最近的失败是:Worker 1在源日志mysql-bin.000002执行事务 'ANONYMOUS',结束日志位置1595341 有关此故障或其他故障的详细信息,请参阅错误日志和/或performance_schema.replication_applier_status_by_worker表。
  22. Skip_Counter: 0
  23. Exec_Master_Log_Pos: 1594966
  24. Relay_Log_Space: 2457347
  25. Until_Condition:
  26. Until_Log_File:
  27. Until_Log_Pos: 0
  28. Master_SSL_Allowed:
  29. Master_SSL_CA_File:
  30. Master_SSL_CA_Path:
  31. Master_SSL_Cert:
  32. Master_SSL_Cipher:
  33. Master_SSL_Key:
  34. Seconds_Behind_Master: NULL
  35. Master_SSL_Verify_Server_Cert:
  36. Last_IO_Errno: 0
  37. Last_IO_Error:
  38. Last_SQL_Errno: 1049
  39. Last_SQL_Error: 协调器停止,因为工作进程中发生错误。 最近的失败是:Worker 1在源日志mysql-bin.000002执行事务 'ANONYMOUS',结束日志位置1595341 有关此故障或其他故障的详细信息,请参阅错误日志和/或performance_schema.replication_applier_status_by_worker表。
  40. Replicate_Ignore_Server_Ids:
  41. Master_Server_Id: 1
  42. Master_UUID: 42e23b0a-9fec-11ea-a6a6-00163e051c80
  43. Master_Info_File: mysql.slave_master_info
  44. SQL_Delay: 0
  45. SQL_Remaining_Delay: NULL
  46. Slave_SQL_Running_State:
  47. Master_Retry_Count: 86400
  48. Master_Bind:
  49. Last_IO_Error_Timestamp:
  50. Last_SQL_Error_Timestamp: 230810 13:58:36
  51. Master_SSL_Crl:
  52. Master_SSL_Crlpath:
  53. Retrieved_Gtid_Set:
  54. Executed_Gtid_Set:
  55. Auto_Position: 0
  56. Replicate_Rewrite_DB:
  57. Channel_Name:
  58. Master_TLS_Version:
  59. Master_public_key_path:
  60. Get_master_public_key: 0
  61. Network_Namespace:
  62. 1行记录,1个警告 (0.00秒)

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

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


主服务器的配置:

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

从服务器的配置:

  1. server-id = 2
  2. max_binlog_size = 100M
  3. # log_bin = /var/log/mysql/mysql-bin.log
  4. binlog_do_db = my_db_name
  5. 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. *************************** 1. row ***************************
  2. Slave_IO_State: Waiting for source to send event
  3. Master_Host: 185.128.xxx.xxx
  4. Master_User: replica
  5. Master_Port: 3306
  6. Connect_Retry: 60
  7. Master_Log_File: mysql-bin.000002
  8. Read_Master_Log_Pos: 2456753
  9. Relay_Log_File: mysql-relay-bin.000003
  10. Relay_Log_Pos: 1595182
  11. Relay_Master_Log_File: mysql-bin.000002
  12. Slave_IO_Running: Yes
  13. Slave_SQL_Running: No
  14. Replicate_Do_DB:
  15. Replicate_Ignore_DB:
  16. Replicate_Do_Table:
  17. Replicate_Ignore_Table:
  18. Replicate_Wild_Do_Table:
  19. Replicate_Wild_Ignore_Table:
  20. Last_Errno: 1049
  21. 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.
  22. Skip_Counter: 0
  23. Exec_Master_Log_Pos: 1594966
  24. Relay_Log_Space: 2457347
  25. Until_Condition: None
  26. Until_Log_File:
  27. Until_Log_Pos: 0
  28. Master_SSL_Allowed: No
  29. Master_SSL_CA_File:
  30. Master_SSL_CA_Path:
  31. Master_SSL_Cert:
  32. Master_SSL_Cipher:
  33. Master_SSL_Key:
  34. Seconds_Behind_Master: NULL
  35. Master_SSL_Verify_Server_Cert: No
  36. Last_IO_Errno: 0
  37. Last_IO_Error:
  38. Last_SQL_Errno: 1049
  39. 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.
  40. Replicate_Ignore_Server_Ids:
  41. Master_Server_Id: 1
  42. Master_UUID: 42e23b0a-9fec-11ea-a6a6-00163e051c80
  43. Master_Info_File: mysql.slave_master_info
  44. SQL_Delay: 0
  45. SQL_Remaining_Delay: NULL
  46. Slave_SQL_Running_State:
  47. Master_Retry_Count: 86400
  48. Master_Bind:
  49. Last_IO_Error_Timestamp:
  50. Last_SQL_Error_Timestamp: 230810 13:58:36
  51. Master_SSL_Crl:
  52. Master_SSL_Crlpath:
  53. Retrieved_Gtid_Set:
  54. Executed_Gtid_Set:
  55. Auto_Position: 0
  56. Replicate_Rewrite_DB:
  57. Channel_Name:
  58. Master_TLS_Version:
  59. Master_public_key_path:
  60. Get_master_public_key: 0
  61. Network_Namespace:
  62. 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:

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

Configuration on the Slave:

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

答案1

得分: 1

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

至少这很容易:

  1. echo "show databases;" | mysql -h dbhost1 > dbsOnDb1
  2. echo "show databases;" | mysql -h dbhost2 > dbsOnDb2
  3. diff dbsOnDb1 dbsOnDb2

(在Linux/Unix上)

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

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

  1. USE local;
  2. CREATE DATABASE newdb;

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

英文:

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

That at least is easy:

  1. echo "show databases;" | mysql -h dbhost1 >dbsOnDb1
  2. echo "show databases;" | mysql -h dbhost2 >dbsOnDb2
  3. 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:

  1. USE local;
  2. 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).

huangapple
  • 本文由 发表于 2023年8月10日 19:53:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/76875518.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定