mysql replication - master to slave

蹲街弑〆低调 提交于 2019-12-11 01:02:17

问题


I have successfully set up a master to slave environment and it is definitely working fine.

The only problem I have is that selecting count from a table, they are not the same BUT selecting after 5 mins from master, 50 rows are created while on the slave, also 50 rows are created (that's why I said i'm sure that is working fine)

Master:

+----------+
| COUNT(*) |
+----------+
|    77634 |
+----------+
1 row in set (0.00 sec)

Slave:

+----------+
| COUNT(*) |
+----------+
|    76932 |
+----------+
1 row in set (0.00 sec)

Any idea why this happened? is it possible that when I changed the slave to point to the master using the 'CHANGE MASTER TO' command, the position of binary log file @ the Master moved already?


回答1:


Try 'SHOW SLAVE STATUS' on the slave to see if any errors have occured.

You can also try load data from master in order to re-establish the synchronization.




回答2:


MySQL replication is not "reliable", nor is it able to automatically re-sync if it goes wrong. There are lots of ways it can go wrong even without unplanned reboots etc.

You need to ACTIVELY monitor it, to stand any chance of it working for any length of time.

You need, at the very least, to do two things:

  1. Check the output of SHOW SLAVE STATUS (on each slave) to ensure that the threads are running, no errors reported and seconds_behind_master is not too much.
  2. Periodically run some kind of consistency check on each slave / master - I recommend mk-table-checksum with the --replication option

And hook the output of those checks up to your monitoring system so that your operations staff get alerted.

Your Ops staff also need to know how to fix it (dump / restore, or some other fix). You will definitely need to write some kind of knowledge-base article for Ops.

I did this before - it is not trivial and you can get it wrong easily.



来源:https://stackoverflow.com/questions/7331776/mysql-replication-master-to-slave

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!