MySQL replication process: each time a write operation is executed, it stores a copy in its own database. At the same time, this write operation is also stored in a binary log file, and save them as events. Therefore, each write operation or modification operation on the front-end data in this database will save an event, we will send the event to another server through port 3306 of the mysql server. The other server will receive the event and save it to a local log file, then read an event from this log file and execute it locally, and save it in the database. This process is called mysql replication.
We will not talk about the installation of mysql. We will directly start the configuration process of master-slave replication:
1. Enable the binary log function of the master and slave, that is, in the mysql master configuration file/usr/local/mysql/etc/my. in cnf, add log_bin = mysql-bin, set server_id of master to 1, and server_id of slave to 2.
Below is the master configuration file
[Root @ localhost ~] # Cat/usr/local/mysql/etc/my. cnf | grep-v ^ # | grep-v ^ $
[Mysqld]
Server_id = 1
Log_bin = mysql-bin
Log-bin-index = mysql-bin.index
Log-error =/var/log/mysql/mysql-error.log
General_log = 1
General_log_file =/var/log/mysql. log
User = mysql
Basedir =/usr/local/mysql
Datadir =/datadir
Port = 3306
Socket =/var/lib/mysql/mysql5.sock
SQL _mode = NO_ENGINE_SUBSTITUTION, STRICT_TRANS_TABLES
Next is the slave configuration file.
[Root @ wordpress ~] # Cat/usr/local/mysql/etc/my. cnf | grep-
V ^ # | grep-v ^ $
[Mysqld]
Server_id = 2
Log_bin = mysql-bin
Log-bin-index = mysql-bin.index
General_log = 1
General_log_file =/var/log/mysql. log
Log-error =/var/log/mysql. error
Basedir =/usr/local/mysql
Datadir =/database
Port = 3306
Socket =/var/run/mysqld/mysql. sock
SQL _mode = NO_ENGINE_SUBSTITUTION, STRICT_TRANS_TABLES
Recommended reading:
Load Nginx in Ubuntu for high-performance WEB Server 5 --- MySQL master/Master Synchronization
Production Environment MySQL master/Master synchronization primary key conflict handling
MySQL Master/Slave failure error Got fatal error 1236
MySQL master-slave replication, implemented on a single server