I can not fully understand what the term "replication" in MySQL means at all.

On Habré, I met the following description of the replication process:

Data changes that occur on the wizard are repeated on the replicas (but not vice versa). Therefore, data change requests (INSERT, UPDATE, DELETE, etc.) are executed only on the master, and data read requests (in other words, SELECT) can be executed both on replicas and on the master.

...

It is important to understand that during replication, it is not the changed data that is transmitted, but only the requests that cause changes.

It turns out that if the replica is initially empty database, then it will be added only data that is added to the master only after replication is turned on? Ie, the data that was added to the master before replication, the replica will not fall?

On the other hand, a lot of where it says that replication is practically the same as synchronization. And this is how I understand, bringing databases to one type ...

    2 answers 2

    Initially, replicas contain a copy of the wizard. If, nevertheless, you set up replication on an empty database, then pretty quickly replication will be broken, since the necessary data for executing queries from bin logs will not be found. Configuring a replica assumes that you are not just copying data from the wizard, but also very accurately setting the coordinates in the bin-logs, starting with which new commands begin to run.

    Ie, the data that was added to the master before replication, the replica will not fall?

    The replication setup procedure itself assumes that you first recreate a copy of the wizard. However, if you manage to avoid this and do not break replication in the future, yes, they will not fall on the replica.

      Let's take a look at what replication in MYSQL means:

      Replication is nothing more than the “ synchronization ” of two and / or more databases on different MySQL servers.

      All database update requests always go to the head server . After a mutated operation on the main server, he places this information in a separate file, from which all the subordinate servers take all the information and add this data to him, synchronizing to the current state of the master.

      Imagine a situation that we have a server that has very important data, for example, a database of a bank. At one moment, we can imagine that the server will burn or fall into some situation when it is not even saved by properly configured replication between disks, and the data at any second of time is very important to us, otherwise we lose a lot of money, morning backup is completely not interesting when the server burned down in the evening.

      Replication of data with zero lag will save us, we create a second server, make a copy of the current database on it and catch up with its requests in automatic mode to the current state of the wizard. The main server will be called the master, and the dependent servers - replicas (slaves). This relationship is called master-slave, when writing is done only on master, and reading can be done from the master or slave.

      Now we have a slave, and we can safely do mysqldump with it without stopping the base for technical work (if it is large), we can carry out heavy requests for reading that do not interfere with the operation of the main base and if the main server fails, we can quickly make a replica master and get minimal downtime.

      We can also set up deferred replication to another server, for example, with a given delay of 1 hour, then we will not encounter problems that some Vasya, who has full access to the database instead of UPDATE WHERE with 3 rows update, wrote just UPDATE, where he updated the entire table .