当前位置:网站首页>MySQL master-slave replication

MySQL master-slave replication

2022-06-22 07:56:00 yolo2016

principle

Simply speaking ,master Write database changes to binary log ,slave Synchronize these binary logs , And according to the binary log data replay operation , Realize data asynchronous synchronization

 Insert picture description here

  1. Change the data on the main library (DDL DML DCL) Log to binary log (Binary Log) in .
  2. For the library I/O The thread copies the logs on the main database to its own relay logs (Relay Log) in .
  3. For the library SQL Thread reads events in relay log , Put it back on the standby database .

 Insert picture description here

Mysql Software installation

yum clean all
yum makecache
cd /sysadmin/manager/LNMP
yum -y install mysql57-community-release-el7-10.noarch.rpm 
yum -y install mysql-community-server
systemctl start mysqld
systemctl enable mysqld
systemctl status mysqld.service

Master slave configuration

 ##Mastar To configure 
[mysqld]
port = 3306           ### 
lower_case_table_names=1                        #  Don't separate case 
log-bin=/var/lib/mysql/mysql-bin                 #  Binary log must be enabled 
server_id = 1  ###
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

service mysqld restart
grant replication slave  on *.* to 'slave'@'%' identified by '123456';
show master status;
## Error reporting reference  https://www.cnblogs.com/mke2fs/p/12386050.html

## Slave To configure 
[mysqld]
port=3306 ##
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
lower_case_table_names=1 ##
server_id = 2  ##
relay_log = /var/lib/mysql/relay.log  ##

service mysqld restart

 # slave Set the copy information on the client 
 change master to  
 master_host='192.168.3.200',master_user='slave',master_password='123456',master_port=3306,master_log_file='mysql-bin.000001',master_log_pos=438;

 start slave;
 
show slave status \G;

Reference resources

Mysql5.7 Master and slave copy build

MySQL Schema backup

原网站

版权声明
本文为[yolo2016]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202220531362175.html