MySQL Master-Slave separation

Source: Internet
Author: User

1. Tools:

Two machines

master:192.168.0.1

slave:192.168.0.2

2, the master configuration

Find MySQL config file, General CentOS is/etc/my.cnf,ubuntu is/etc/mysql/mysql.conf.d/mysqld.cnf

Skip to configuration under [Mysqld]

# can be commented # unique Node ID in schemalog_bin=mysql-# open binlogbinlog-ignore-db=mysql  #  Databases that do not need tobe replicated binlog-do-db=ufind_db   # databases to replicate

Restart Master

Service MySQL Restart

Go to MySQL command line, add user

CREATE USER 'zhylioooo'@'%'Identified by '123456';GRANT REPLICATIONSLAVE on *.*  to 'zhylioooo'@'%';

Export the master database

Lock the database to make it readable only

 with READ LOCK;

Database files Everywhere

Mysqldump-u root-p--all-databases--master-data > Dbdump.sql

Unlocking a Database

UNLOCK TABLES;

View master's binary record file and the location of the file's current record

SHOW MASTER STATUS;
+ ------------------+----------+--------------+------------------+-------------------+ | File    | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | + ------------------+----------+--------------+------------------+-------------------+ | mysql-bin.000001 |  1050 |    |     |     | + ------------------+----------+--------------+------------------+-------------------+ 1 row in set (0.00 sec)3, slave configuration slave configuration focus
# unique Node ID in schema, larger than master log_bin=mysql-# Open Binlog

Restart MySQL

Import the master exported database file to make the database consistent

Mysql-u Root-p < Dbdump.sql

Enter MySQL to connect the slave to master

STOP SLAVE; Change MASTER to  -Master_host='192.168.0.1',  -Master_user='zhylioooo',  -Master_password='123456',  -Master_log_file='mysql-bin.000001',  -Master_log_pos=1050; START SLAVE;

4. Cluster strategy: https://www.cnblogs.com/KTblog/p/5122825.html

MySQL Master-Slave separation

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.