MySQL Master-slave replication

Source: Internet
Author: User

Master-slave Replication steps


1: Open the main library binlog function

See if 3306 is turned on

grep log-bin/etc/my.cnf

See if it's not the same

2: Make sure the Server-id is different

grep server-id/etc/my.cnf

grep server-id/data/3307/my.cnf

3: User rep for Master library authorized replication

Grant Replication Slave on * * to [e-mail protected] ' 192.168.1.102 ' identified by ' 2017 ';

See if authorization is successful

4: Lock table, view Binlog location point

Lock table to ensure database consistency

Flush table with read lock;

Show master status; Look at the backup point

Show master status;

+------------------+----------+--------------+------------------+

| File | Position | binlog_do_db | binlog_ignore_db |

+------------------+----------+--------------+------------------+

|      mysql-bin.000053 |              339 |                  | |

+------------------+----------+--------------+------------------+

5. New open window export fully prepared

Mysqldump-uroot-p2017-a-B--events-s/tmp/mysql.sock|gzip >/home/chaofu/rep_bak_$ (date +%F). sql.gz


6:unlock Table Release Lock


From library:

1: Make sure the Server-id is different

2: Restore the data from the main library to the library

Gzip-d rep_bak.sql.gz

Mysql-uroot-p-s/data/3307/mysql.sock

3: Find location point, configure Master.info

Change MASTER to

Master_host= ' 192.168.1.102 ',

master_port=3306,

Master_user= ' rep ',

master_password= ' 2017 ',

Master_log_file= ' mysql-bin.000053 ',

master_log_pos=339;

Find/data/3307/data-type-f-name "*.info"


4: Turn on the backup switch

Start slave;

show slave status \g;

Two threads from a library

5: Test


Master-slave replication schematic diagram


This article is from the "9124122" blog, please be sure to keep this source http://9134122.blog.51cto.com/9124122/1983933

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.