MySQL master-slave synchronization configuration under Mac

Source: Internet
Author: User

I. Environmental description

Two mac,mysql Environment Master is 5.7.20,slave is 5.7.21
Master ip:172.21.127.10
Slave ip:172.21.127.12

Second, Master machine configuration

1. Change the configuration file

# Default Homebrew MySQL server config[mysqld]# Only allow connections from localhostbind-address =  172.21.127.10log-error=/var/log/mysqld.logpid-file=/var/run/mysqld/mysqld.pidserver-id = 1log-bin = mysql-binbinlog-format = ROW #选择row模式

2. Restart MySQL to make the above configuration effective

3. Create a user for master-slave synchronization, authorize it, and specify that the user can only log on to the 172.21.127.12 machine.

grant  replication  slave  on  *.*  to  ‘slave1‘@‘172.21.127.12‘  identified  by  "slavepass";

4, in order to ensure the database consistency of the master-slave library, you need to first read the lock to make it read-only

FLUSH TABLE WITH READ LOCK

5, record the master's Binlog log file, and the offset

6. Export the existing data on master and enter the directory where you want to export the SQL file, and execute the following statement.

mysqldump -uroot -proot --all-databases > db.sql

7. Unlock Master's Read lock

UNLOCK TABLES;

8. Copy the Db.sql to the slave machine

Three, slave machine configuration

1, first or modify the configuration file. Refer to the configuration on the master machine. Will server-id modify, cannot repeat, if not configured Server-id a moment start slave will error

2. Restart MySQL

3. Import the written db.sql into the database

mysqldump -u root -p 要导出的数据库名>名字随意.sql #在这里直接mysqldump -root -proot < /Users/my/db.sql

4, make slave and master to establish its synchronization, this is a key step

STOP SLAVE;CHANGE MASTER TO    MASTER_HOST=‘172.21.127.10‘,    MASTER_USER=‘slave1‘,    MASTER_PASSWORD=‘slavepass‘,    MASTER_LOG_FILE=‘mysql-bin.000003‘,    MASTER_LOG_POS=1791;START SLAVE;
Iv. Summary

After the above steps you can simply realize master-slave synchronization, if there is a problem, you can look at the previous configuration of the Log-error log, encounter problems more log ~

MySQL master-slave synchronization configuration under Mac

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.