MySQL Master-Slave Replication – Ensuring Data Consistency

MySQLreplication

I have setup a master-slave replication with mysql 5.7 and GTID.

GTID should be more "safe" than the older way where each statement alone was replicated right?

But when replicating with GTID can I then check the data consistency on the slave just by checking SHOW SLAVE STATUS\G ?

Or do I need to checksum each row in each table to make sure everything is replicated correctly?

Best Answer

Before I address your question, some terminology issues...

GTID uniquely identifies each thing replicated. This is an improvement on the previous Replication technology -- but mostly when you have multiple machines and need to recover from some kind of failure. It helps automate things.

bin_log_format = STATEMENT or ROW or MIXED refers to what is transferred from Master to Slave. STATEMENT (SBR) is the old way; ROW (RBR) is the new way. There are many subtle reasons why RBR is 'better'.

SHOW SLAVE STATUS provides, among other things, whether or not replication has stopped due to some error. It reports a crude measure of staleness (Seconds_Behind_Master), but not "consistency" (whether the changes arrived and were correctly applied).

You do not need a checksum on each row. It would be clumsy for you to add such. The network layer (TCP/IP, etc) does checksumming to 'guarantee' delivery and to validate the contents of the delivery.

If you want to do your own consistency checking, I recommend Percona's pt-table-checksum . It takes care of a lot of end-cases that are not obvious to someone starting out to do the checking himself.