1. Configuration file
A library configuration file:
In the /etc/my.cnf [mysqld] section add: server_id=1 # log_bin log path, format and deletion time (30 days) log_bin=/var/lib/mysql/mysql-bin binlog_format='MIXED' # ROW STATEMENT MIXED
expire_logs_days=30 # Log path synchronized from the main library relay-log=/var/lib/mysql/relay-bin
B library configuration file
In the /etc/my.cnf [mysqld] section add: server_id=2 # log_bin log path , format and deletion time (30 days)
log_bin=/var/lib/mysql/mysql-bin binlog_format='MIXED' # ROW STATEMENT MIXED
expire_logs_days=30
# log path
relay synchronized from the main library -log=/var/lib/mysql/relay-bin
2. Configure synchronization users on A and B (master configuration)
login database
mysql -u root -p
Create Create a user.
create user 'repl'@'192.168.122.%' identified by '123456';
Give it replication slave permissions on the primary server.
grant replication slave on *.* to 'repl'@'192.168.122.%';
3. View the current binlog file name and position on A and B
A、
mysql> show master status; +------------------+----------+--------------+------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | +------------------+----------+--------------+------------------+ | mysql-bin.000006 | 106 | | | +------------------+----------+--------------+------------------+
B、
mysql> show master status;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000003 | 112 | | |
+------------------+----------+--------------+------------------+
4. Configure the Slave configuration on A and B respectively
A, 192.168.122.37 is B's IP
CHANGE MASTER TO MASTER_HOST= ' 192.168.122.37 ' , MASTER_USER= ' repl ' , MASTER_PASSWORD= ' 123456 ' , MASTER_LOG_FILE= ' mysql-bin.000003 ' , MASTER_LOG_POS= 112 ;
START SLAVE; show
slave status\G;
All Yes indicates that the configuration is normal.
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
B. 192.168.122.36 is A's IP
CHANGE MASTER TO MASTER_HOST='192.168.122.36', MASTER_USER='repl', MASTER_PASSWORD='123456', MASTER_LOG_FILE='mysql-bin.000006', MASTER_LOG_POS=106;
START SLAVE; show
slave status\G;
All Yes indicates that the configuration is normal.
Slave_IO_Running: Yes
Slave_SQL_Running: Yes