mysql5.5 master slave of Replication configuration method

  • 2020-05-12 06:18:19
  • OfStack

1 master 1 from:
Master:
OS:centos release 5.6 DB:mysql 5.5.8 IP:192.168.1.2
Slave:
OS:centos release 5.6 DB:mysql 5.5.8 IP:192.168.1.3
Modify the host Master configuration file (/etc/ my.cnf)
 
[mysqld] 
// There must be at least server-id , and log-bin two  
server-id=1 
log-bin=/var/lib/mysql/mysql-bin 
datadir=/var/lib/mysql 
// In order to use transactions InnoDB Maximum persistence and in replication 1 Sex, you should specify innodb_flush_log_at_trx_commit=1,sync_binlog=1 options  
innodb_flush_log_at_trx_commit=1 
sync_binlog=1 

Create a user with replication privileges on host Master
mysql > create user repl_user@192.168.1.3;
mysql > grant replication slave on *.* to repl_user@192.168.1.3 identified by '123456';
Lock the host and record the location of the binary log (this will be used when setting the slave later)
mysql > flush tables with read lock;
mysal > show master status;
File: mysql-bin.000013 Position: 7863951
Copy the host database (test) to the slave
shell > /usr/bin/mysqldump test -uroot -padmin --opt | mysql test -uroot -padmin -h 192.168.1.3
Reopen the host Master write function
mysql > unlock tables;


Modify the slave Slave configuration file (/etc/ my.cnf)
 
[mysqld] 
server-id=2 // It must be 1 to 2 the 32 Between powers 1 Integer, and must be with the host Master the server-id Don't 1 sample  
relay-log-index=slave-relay-bin.index 
relay-log=slave-relay-bin 
replicate-do-db=test // Specify replication database  
datadir=/var/lib/mysql 

The slave Slave initializes the copy
 
mysql>slave stop; 
mysql>change master to master_host='192.168.1.2', 
->master_user='repl_user', 
->master_password='123456', 
->master_log_file='mysql-bin.000013', 
->master_log_pos=7863951; 

Open the copy
mysql > start slave;
View replication status
mysql > show slave status\G
Test copy:
Perform sql operations on the test database in the host master, and then check to see if the slave test database generates synchronization.
An Slave SQL error that causes synchronization to get stuck
 
mysql>slave stop; 
mysql>set GLOBAL SQL_SLAVE_SKIP_COUNTER=1; 
mysql>slave start; 

Related articles: