Search code examples
mysqldatabasemariadbreplicationdatabase-replication

How to synchronize replicationDB with masterDB in MariaDB


I created replicaDB and I've got a problem. While I was creating it, I did some steps below

  1. FLUSH TABLES WITH READ LOCK; on masterDB
  2. mysqldump command as well to make a backup
  3. import backup into replicaDB
  4. RESET SLAVE; ,did CHANGE MASTER command, and START SLAVE on replicaDB
  5. UNLOCK TABLES; on masterDB

Through those steps, the replicaDB has got the same data as masterDB has. However, a new record(id = 159), due to cron job, was inserted into masterDB after "UNLOCK TABLES;" and it wasn't synchronized in replicaDB. From id = 160, records are synchronized in replicaDB now.

How should I solve this problem?

masterDB:192.168.30.123

replicationDB:192.168.30.131

database:todo

replication user:repli4

masterDB's set up
[mysqld]
 bind-address = 0.0.0.0
 binlog_format = ROW
 max_binlog_size = 128M
 expire_logs_days = 7
 log-error=/var/log/mysql/error.log
 log-bin-trust-function-creators = true
 log-bin
 binlog-format = mixed
 log-basename =master
 server_id = 1
 log_bin = /var/log/mysql/mysql-bin.log 
replicationDB's set up
[mysqld]
bind-address    = 0.0.0.0
binlog_format = ROW
max_binlog_size = 128M
expire_logs_days = 7
log-error=/var/log/mysql/error.log
log-bin-trust-function-creators = true

server_id = 5
slave-skip-errors = all
replicate-do-db = todo
read_only = ON
log_bin = mysql-bin
rpl_semi_sync_slave_enabled=ON

records in replicaDB

SHOW SLAVE STATUS/G

Could anyone help me, please?


Solution

  • It seems like your replica is still reading just fine from the slave status, just a data de-sync issue. The simplest thing to do here is to redo the backup and restore. After the restore, your replica should match with your master data and your replication setup should be unaffected.

    1. FLUSH TABLES WITH READ LOCK; on masterDB
    2. backup master on masterDB via mysqldump -uusername -p database_name > master_backup.sql
    3. import backup into replicaDB via mysql -uusername -p database_name < master_backup.sql
    4. UNLOCK TABLES; on masterDB