I wanted to ask the experienced how MySQL "Master-Slave" replication works more precisely, since I don't understand the following:
Suppose I have two lists of records that are numbered 1 through 5, but the values and data contained in the two lists are different.
As I understand it, what the replication would do would be to move the 5 missing records from each table to the other so that the two remain the same. TRUE?.
In this case, would there be two tables of 10 registers left or would you replace the 5 from the slave to put the 5 from the master instead?
Perhaps I was confused, my main doubt is what happens with the keys of each table.
How specifically does replication work?
It doesn't work as you describe in the question. Below I will explain, without going into technical details, how it is done.
The operation of the replication is based on the binary or transaction log generated by the MySQL server.
Any modification made to the database is written in said registry, and this registry is sent in the form of a stream of data at the request of the connected secondary servers, which will replicate the changes that are reflected in it.
In the official documentation you can find the following:
In Spanish:
In Section 17.2 Replication Implementation you also have the following:
In Spanish:
In addition, you must understand that if modifications are made to the replicas (let's use the terminology "primary/replica" instead of "master/slave") that may collide with the process of replicating the changes of the primary, the replication will stop with an error message and will have to be corrected manually before it can continue:
In Spanish:
This behavior is not unique or exclusive to MySQL or its replication, but it is a very common component in the vast majority of database managers (to be used in replication tasks or not):