MySQL Master-slave replication

Source: Internet
Author: User
Tags unique id

0. Description

MySQL service version best consistent, inconsistent may cause problems
master database ip:192.168.0.10
Slave database ip:192.168.0.11

1. Modify Master server Master

vi /etc/my.cnf[mysqld]log-bin=mysql-bin   #[must be] enable binary log server-id=10         #[must] server unique ID, default is 1, usually take IP last paragraph

2, modify from the server slave

vi /etc/my.cnf[mysqld]log-bin=mysql-bin   #[must be] enable binary log server-id=          #[must] server unique ID, default is 1, usually take IP last paragraph

3. Restart MySQL Service

Service mysqld Restart    #如果修改了my. cnf

4. Establish an account on the primary server and authorize slave

' slave '@'192.168.0.11'123456'; flush privileges;

5, log on to the master server MySQL, query the status of master

Mysql>Show master status; +------------------+----------+--------------+------------------+| File             | Position | binlog_do_db | binlog_ignore_db |+------------------+----------+--------------+------------------+| Mysql-bin. 000001 |      308 |              |                  | +------------------+----------+--------------+------------------+1 in Set (0.00 sec)

Note: Do not operate the master server MySQL again after performing this step to prevent the change of the primary server state value

6, configuration from the server slave

 mysql> Change MASTER to Master_host= "   " , --Master_ User=  slave    --Master_password= 123456   " , --Master_log_file = "  '  

7. Accidental

Accident 1: Host shutdown, standby machine normal: After the host restarts, the standby machine can still be replicated in a normal synchronization.

Accident 2: host does not stop, standby machine shutdown: After the standby machine restarts, the standby machine to open the manual copy function as follows:

mysql> start slave;

Accident 3: host shutdown, standby shutdown:

(1) First open slave, start MySQL, enter MySQL
mysql> stop Slave;
Mysql> show slave status \g; Make a note of the last POS with a binlog value of mysql-bin.000079, 875653787

(2) Re-specify the master target:
mysql> Change Master tomaster_user= ' rel ',
Master_password= ' slavepd1012301151 ',
Master_host= ' 192.168.250.20,
Master_log_file= ' mysql-bin.000079 ',
master_log_pos=875653787;

(3) Start Master
(4) Enter slave, start the copy function.

8. Reference

Http://www.cnblogs.com/jirglt/p/3549047.html
http://369369.blog.51cto.com/319630/790921/
http://blog.itpub.net/23490154/viewspace-1062530/

MySQL Master-slave replication

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.