Perform SQL operations on the test database on the master node, and check whether the test database on the slave node generates synchronization.
Perform SQL operations on the test database on the master node, and check whether the test database on the slave node generates synchronization.
One master and one slave:
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)
The Code is as follows:
[Mysqld]
// At least two items are required: server-id and log-bin.
Server-id = 1
Log-bin =/var/lib/mysql-bin
Datadir =/var/lib/mysql
// To use the maximum persistence and consistency of the InnoDB in the transaction in the replication, you should specify the innodb_flush_log_at_trx_commit = 1, sync_binlog = 1 option
Innodb_flush_log_at_trx_commit = 1
Sync_binlog = 1
Create a user with the copy permission on the 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 '2013 ';
Lock the host and record the location of the binary log (used later when the slave is set)
Mysql> flush tables with read lock;
Mysal> show master status;
File: mysql-bin.000013 Position: 7863951
Copy host database (test) to slave
Shell>/usr/bin/mysqldump test-uroot-padmin -- opt | mysql test-uroot-padmin-h 192.168.1.3
Re-enable the Master write operation function.
Mysql> unlock tables;
Modify the Slave server Slave configuration file (/etc/my. cnf)
The Code is as follows:
[Mysqld]
Server-id = 2 // it must be an integer between the power of 1 and the power of 2, and must be different from the server-id of the host Master.
Relay-log-index = slave-relay-bin.index
Relay-log = slave-relay-bin
Replicate-do-db = test // specify to copy the database
Datadir =/var/lib/mysql
Slave initialization and Replication
Mysql> slave stop;
Mysql> change master to master_host = '192. 168.1.2 ',
-> Master_user = 'repl _ user ',
-> Master_password = '123 ',
-> Master_log_file = 'mysql-bin.000013 ',
-> Master_log_pos = 7863951;
Enable replication
Mysql> start slave;
View copy status
Mysql> show slave status \ G
Test replication:
Perform SQL operations on the test database on the master node, and check whether the test database on the slave node generates synchronization.