Mysql5.5master-slave (Replication) configuration method _ MySQL
Source: Internet
Author: User
Mysql5.5master-slave (Replication) configuration method bitsCN.com one master 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)
[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)
[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
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.
Slave SQL error causes synchronization to get stuck
Mysql> slave stop;
Mysql> set GLOBAL SQL _SLAVE_SKIP_COUNTER = 1;
Mysql> slave start;
BitsCN.com
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service