Mysql5.5 master-slave (Replication) master-slave Configuration

Source: Internet
Author: User

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)
Copy codeThe 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)
Copy codeThe 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.

Related Article

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.