mysqldatabasereplicationdatabase-replicationmulti-master-replication

MySQL slave replication not writing binlog file


I have installed 3 MySQL Server (8.0.29-0ubuntu0.22.04.2) to create a master-slave replication like

Master -> Slave -> Secondary Slave

My issue is when i change database in master it is replicated in Slave by binlog writen by Master but that change done on Slave is not getting replicated on Secondary Slave

i have enabled log_slave_updates / log_replica_updates in slave but nothing worked.

[mysqld]

# bind-address          = 127.0.0.1
server-id               = 4
log_bin                 = /var/log/mysql/mysql-bin.log
binlog_expire_logs_seconds      = 2592000
max_binlog_size   = 100M
binlog_do_db            = replication_db_1
binlog_do_db            = replication_db_2
relay-log = /var/lib/mysql/ubuntu-vm8-relay-bin.log

log_slave_updates
log_replica_updates
# binlog_ignore_db      = include_database_name

Same thing happens for circular Master Master Replication with 3 servers, create database xxxxx; alone replicating all 3 nodes, but not table creation query getting replicated more than one level of hierarchy.

mysql> show global variables like "%log%";
+------------------------------------------------+-------------------------------------------+
| Variable_name                                  | Value                                     |
+------------------------------------------------+-------------------------------------------+
| activate_all_roles_on_login                    | OFF                                       |
| back_log                                       | 151                                       |
| binlog_cache_size                              | 32768                                     |
| binlog_checksum                                | CRC32                                     |
| binlog_direct_non_transactional_updates        | OFF                                       |
| binlog_encryption                              | OFF                                       |
| binlog_error_action                            | ABORT_SERVER                              |
| binlog_expire_logs_auto_purge                  | ON                                        |
| binlog_expire_logs_seconds                     | 2592000                                   |
| binlog_format                                  | MIXED                                     |
| binlog_group_commit_sync_delay                 | 0                                         |
| binlog_group_commit_sync_no_delay_count        | 0                                         |
| binlog_gtid_simple_recovery                    | ON                                        |
| binlog_max_flush_queue_time                    | 0                                         |
| binlog_order_commits                           | ON                                        |
| binlog_rotate_encryption_master_key_at_startup | OFF                                       |
| binlog_row_event_max_size                      | 8192                                      |
| binlog_row_image                               | FULL                                      |
| binlog_row_metadata                            | MINIMAL                                   |
| binlog_row_value_options                       |                                           |
| binlog_rows_query_log_events                   | OFF                                       |
| binlog_stmt_cache_size                         | 32768                                     |
| binlog_transaction_compression                 | OFF                                       |
| binlog_transaction_compression_level_zstd      | 3                                         |
| binlog_transaction_dependency_history_size     | 25000                                     |
| binlog_transaction_dependency_tracking         | COMMIT_ORDER                              |
| expire_logs_days                               | 0                                         |
| general_log                                    | OFF                                       |
| general_log_file                               | /var/lib/mysql/ubuntu-vm8.log             |
| innodb_api_enable_binlog                       | OFF                                       |
| innodb_flush_log_at_timeout                    | 1                                         |
| innodb_flush_log_at_trx_commit                 | 1                                         |
| innodb_log_buffer_size                         | 16777216                                  |
| innodb_log_checksums                           | ON                                        |
| innodb_log_compressed_pages                    | ON                                        |
| innodb_log_file_size                           | 50331648                                  |
| innodb_log_files_in_group                      | 2                                         |
| innodb_log_group_home_dir                      | ./                                        |
| innodb_log_spin_cpu_abs_lwm                    | 80                                        |
| innodb_log_spin_cpu_pct_hwm                    | 50                                        |
| innodb_log_wait_for_flush_spin_hwm             | 400                                       |
| innodb_log_write_ahead_size                    | 8192                                      |
| innodb_log_writer_threads                      | ON                                        |
| innodb_max_undo_log_size                       | 1073741824                                |
| innodb_online_alter_log_max_size               | 134217728                                 |
| innodb_print_ddl_logs                          | OFF                                       |
| innodb_redo_log_archive_dirs                   |                                           |
| innodb_redo_log_encrypt                        | OFF                                       |
| innodb_undo_log_encrypt                        | OFF                                       |
| innodb_undo_log_truncate                       | ON                                        |
| log_bin                                        | ON                                        |
| log_bin_basename                               | /var/log/mysql/mysql-bin                  |
| log_bin_index                                  | /var/log/mysql/mysql-bin.index            |
| log_bin_trust_function_creators                | OFF                                       |
| log_bin_use_v1_row_events                      | OFF                                       |
| log_error                                      | /var/log/mysql/error.log                  |
| log_error_services                             | log_filter_internal; log_sink_internal    |
| log_error_suppression_list                     |                                           |
| log_error_verbosity                            | 2                                         |
| log_output                                     | FILE                                      |
| log_queries_not_using_indexes                  | ON                                        |
| log_raw                                        | OFF                                       |
| log_replica_updates                            | ON                                        |
| log_slave_updates                              | ON                                        |
| log_slow_admin_statements                      | OFF                                       |
| log_slow_extra                                 | OFF                                       |
| log_slow_replica_statements                    | OFF                                       |
| log_slow_slave_statements                      | OFF                                       |
| log_statements_unsafe_for_binlog               | ON                                        |
| log_throttle_queries_not_using_indexes         | 0                                         |
| log_timestamps                                 | UTC                                       |
| max_binlog_cache_size                          | 18446744073709547520                      |
| max_binlog_size                                | 104857600                                 |
| max_binlog_stmt_cache_size                     | 18446744073709547520                      |
| max_relay_log_size                             | 0                                         |
| relay_log                                      | /var/lib/mysql/ubuntu-vm8-relay-bin.log   |
| relay_log_basename                             | /var/lib/mysql/ubuntu-vm8-relay-bin       |
| relay_log_index                                | /var/lib/mysql/ubuntu-vm8-relay-bin.index |
| relay_log_info_file                            | relay-log.info                            |
| relay_log_info_repository                      | TABLE                                     |
| relay_log_purge                                | ON                                        |
| relay_log_recovery                             | OFF                                       |
| relay_log_space_limit                          | 0                                         |
| slow_query_log                                 | ON                                        |
| slow_query_log_file                            | /var/log/mysql/mysql-slow.log             |
| sql_log_off                                    | OFF                                       |
| sync_binlog                                    | 1                                         |
| sync_relay_log                                 | 10000                                     |
| sync_relay_log_info                            | 10000                                     |
| terminology_use_previous                       | NONE                                      |
+------------------------------------------------+-------------------------------------------+
90 rows in set (0.00 sec)

Slave 1 :

mysql> show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for source to send event
                  Master_Host: 192.168.203.88
                  Master_User: replicator
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000002
          Read_Master_Log_Pos: 157
               Relay_Log_File: ubuntu-vm8-relay-bin.000006
                Relay_Log_Pos: 373
        Relay_Master_Log_File: mysql-bin.000002
             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: 157
              Relay_Log_Space: 635
              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: 0
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: 1
                  Master_UUID: 0f426665-12fa-11ed-b411-080027e54a70
             Master_Info_File: mysql.slave_master_info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Replica has read all relay log; waiting for more updates
           Master_Retry_Count: 86400
                  Master_Bind: 
      Last_IO_Error_Timestamp: 
     Last_SQL_Error_Timestamp: 
               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: 1
            Network_Namespace: 
1 row in set, 1 warning (0.00 sec)

Slave 2 (secondary slave )

mysql> show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for source to send event
                  Master_Host: 192.168.202.120
                  Master_User: replicator
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000002
          Read_Master_Log_Pos: 157
               Relay_Log_File: ubuntu-vm7-relay-bin.000005
                Relay_Log_Pos: 326
        Relay_Master_Log_File: mysql-bin.000002
             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: 157
              Relay_Log_Space: 757
              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: 0
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: 4
                  Master_UUID: d2dc13dc-12f9-11ed-b7d6-080027d93010
             Master_Info_File: mysql.slave_master_info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Replica has read all relay log; waiting for more updates
           Master_Retry_Count: 86400
                  Master_Bind: 
      Last_IO_Error_Timestamp: 
     Last_SQL_Error_Timestamp: 
               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: 1
            Network_Namespace: 
1 row in set, 1 warning (0.01 sec)

Any idea how to fix this?

Thanks!!


Solution

  • if you add binlog_do_db in mysql.conf, only database level changes like create database xxx and drop database xxx only affected in all 3 mysql servers [Master - Master - Master], table level changes are not affecting for the 2 level of the triangular master master replication setup

    just comment out binlod_do_db, and restart the mysql

    all the database level, table level changes gets affected in all 3 node in the replication group

    https://dev.mysql.com/doc/refman/5.7/en/replication-options-binary-log.html#option_mysqld_binlog-do-db