mysql5.5 Master-slave (Replication) configuration method _mysql

Source: Internet
Author: User
One main one 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 host master configuration file (/etc/my.cnf)
Copy Code code as follows:

[Mysqld]
At least two Server-id and Log-bin.
Server-id=1
Log-bin=/var/lib/mysql/mysql-bin
Datadir=/var/lib/mysql
In order to use the InnoDB of the transaction for maximum persistence and consistency in 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 replication permissions in 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 (used when setting up from the machine)
Mysql>flush tables with read lock;
Mysal>show Master status;
file:mysql-bin.000013 position:7863951
Copy host database (test) to from machine
Shell>/usr/bin/mysqldump Test-uroot-padmin--opt | MySQL test-uroot-padmin-h 192.168.1.3
Re-open Host Master write function
Mysql>unlock tables;


Modify the slave configuration file (/ETC/MY.CNF) from the machine
Copy Code code as follows:

[Mysqld]
server-id=2//Must be an integer between 1 and 2 of 32 sides and must be different from the Server-id of host Master
Relay-log-index=slave-relay-bin.index
Relay-log=slave-relay-bin
Replicate-do-db=test//Specify Replication database
Datadir=/var/lib/mysql

Initializing replication from machine slave
Copy Code code as follows:

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;

Turn on replication
Mysql>start slave;
View replication Status
Mysql>show slave Status\g
Test replication:
Perform SQL operations on the test database in host master and see if synchronization is generated from the machine test database.
An approach to Slave SQL errors causing synchronization to jammed
Copy Code code as follows:

Mysql>slave stop;
Mysql>set GLOBAL sql_slave_skip_counter=1;
Mysql>slave start;

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.