MySQL Master-slave replication

Environment Description

        centos7.3、MySQL5.7

Foreword

        MySQL installation before the reference article https://www.jianshu.com/p/452aa99c7476 have to explain.

basic concept

        MySQL built-in replication is the basis for building large, high-performance applications. MySQL mechanism distributed to hundreds of millions of up to a plurality of systems, such a distribution is by copying data of a MySQL host to other hosts (the Slave), and the instructions again achieved. During replication server acts as a server, and one or more other servers act as from the server. A master index server writes binary log will update and maintain files to track log cycle. These log records can be sent from the server to update. When a connection from the master server, it informs the primary server, any updates since then received from the server from the occurrence of the last successful location update server reads in the log, the primary server notifies the like and then blocked new update . Note that when you copy, all updates on replicated tables must be on the primary server. Otherwise, you have to be careful to avoid conflicts between updates for the user list on the main server and update the table on the server carried out

Master-slave replication

A, modify the primary (master) server

        If I wrote the article in accordance with MySQL installed, then the next my.cnf configuration file in / etc / directory. Under If not, can command whereis search by adding the following configuration in my.cnf configuration file

server_id=1 #指定MySQL的id
log-bin=mysql-bin #开启二进制日志文件
复制代码

        Second, create a replication account

        Executes the command on the primary server (here allow access all the addresses, the address provided from the recommendation server)

GRANT REPLICATION SLAVE ON *.* to 'replication'@'%' identified by 'Abc123...';
复制代码

        Third, modified from (slave) server

server_id=2
log-bin=mysql-bin
binlog_do_db=db_test#表示要同步的数据库
复制代码

Description: binlog-ignore-db = test said they did not represent test database synchronization binlog_do_db = db_test # database to be synchronized

        Fourth, restart MySQL

Master and slave servers are restarted

service mysqld restart
复制代码

        Fifth, view master server status

show master status
复制代码

The results are as follows:

Here are some information needs to be recorded in the configuration from the server when you need to use # Sixth, from the configuration server (Master server connection)

change master to master_host='192.168.74.129',master_user='replication',master_password='Abc123...',master_log_file='mysql-bin.000001',master_log_pos=2041;
复制代码

master_host is ip master_port master server = 3306 (there is no configuration, default 3306) master_user: Master server an authorized user, that is, the user master_password created earlier Master: Master server authorization password master_log_file corresponding to the user: Master binlog file name master_log_pos: Master Postion value binlog file on position value, make a note here: If the primary server is already a lot of data, it would first need to back up data from the primary server to the server, and then use the command show master status records need to get started synchronization position. # Seven starts copying the implementation from the server

start slave
复制代码

The stop command is: stop slave; # Eight, from the server to view status

show slave status\G;
复制代码

Results circled figure two is configured from a front yes replicate successfully. If the configuration fails, you can go to the MySQL log file to see fail information, you can also view a brief error message via the command:
This is what I just configure the master server from the wrong times, mainly due to the conflict UUID of the server MySQL server, because I was copied from the server on the primary server from the past. To /var/lib/mysql/auto.cnf modifications. # Verify the status of the main results from the present:
Create a table below, see if you can synchronize the past:
# View from the server
We can see already passed sync and sync

Reproduced in: https: //juejin.im/post/5d08f45051882533e13373f0

Guess you like

Origin blog.csdn.net/weixin_34055910/article/details/93181308