MySQL master-slave Introduction, configuration master, configuration from

Source: Internet
Author: User

mysql主从介绍

MySQL master-slave is also called replication, AB replication. Simply speaking is a and b two machines from the back, write the data on a, the other B will follow the writing data, both data real-time synchronization

MySQL主从是基于binlog的,主上须开启binlog才能进行主从。 主从过程大致有3个步骤 1)主将更改操作记录到binlog里 2)从将主的binlog事件(sql语句)同步到从本机上并记录在relaylog里 3)从根据relaylog里面的sql语句按顺序执行
主上有一个log dump线程,用来和从的I/O线程传递binlog从上有两个线程,其中I/O线程用来同步主的binlog并生成relaylog,另外一个SQL线程用来把relaylog里面的sql语句执行一遍两种情况:一种是做备份用,一种是作为读用
                                                      配置主

The following configures one master one from:
One machine (192.168.37.130) as the main, install MySQL

Modify MY.CNF, add server-id=130 and LOG_BIN=ZENWEN1 (optionally defined)

#vim /etc/my.cnf                                           //编辑配置文件

修改完配置文件后,启动或者重启mysqld服务 #/etc/init.d/mysqld restart
创建用作同步数据的用户 #mysql -uroot -p5650895              //登录mysql#grant replication slave on *.* to ‘repl‘@slave_ip identified by ‘5650895‘; #flush tables with read lock;                        //将mysql锁住不写数据
#show master status;

                                               配置从
首先安装mysql 查看my.cnf,配置server-id=132,要求和主不一样 修改完配置文件后,启动或者重启mysqld服务 #/etc/init.d/mysqld restart              //重启服务


Check the error log to find the reason, such as continue operation

And go to the Lord to execute unlock tables, unlock


Check the error log to find out why

2018-01-10 14:55:18 4470 [ERROR] Slave I/O: Fatal error: The slave I/O thread stops because master and slave have equal MySQL server UUIDs; these UUIDs must be different for replication to work. Error_code: 1593
找到原因,是因为使用的克隆的原因,执行操作#cd /data/mysql/#mv auto.cnf  auto.cnf.bak#/etc/init.d/mysqld restart


See if there is
Slave_io_running:yes
Slave_sql_running:yes

MySQL master-slave Introduction, configuration master, configuration from

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.