Mysql Master/Slave Mode

Source: Internet
Author: User

Implementation Mechanism of mysql Replication
1) The primary mysql first saves the operation statement in the bin-log.
2) start a process or thread from the server to initiate a request to the master mysql.
3) copy the operation statements in the bin-log of the primary mysql from the relay-log of mysql.
4) execute these operation statements from the top.
Configuration
The main mysql here mainly introduces the content to be changed (the master and slave are changed from the independent mode of the master)
1) Add or modify the following content in/etc/my. cnf:
Bin-log = mysql. bin-log # defines the file name of bin-log (stored in the data directory by default)
Bin-log-index = mysql. bin-log.index # define the file name of bin-log-index
Binlog-format = mixed # define the binlog format
Server-id = 1 # Make sure that the server-id of the master mysql is smaller than the server-id of the slave mysql
2) Start mysql and configure
# Service mysqld start
# Mysql # Enter mysql
# Set password for root @ 'localhost' = password ('mim ');
# Set password for root @ '2014. 0.0.1 '= password ('mim ');
# Grant replication slave, replication client on *. * to username @ 'IP' identified by 'mima'; # grant username the permission to copy
# Flush privileges;
# Show master status; # view the status of the master mysql instance
From mysql
1) Add or modify the following content in/etc/my. cnf:
Relay-log = mysql. relay-log # define the relay-log File Name (stored in the data directory by default)
Relay-log-index = mysql. relay-log.index # define the relay-log-index file name
Server-id = 11 # must be greater than the server-id of the primary mysql
2) Start mysql and configure
# Service mysqld start
# Mysql # Enter mysql
# Set password for root @ 'localhost' = password ('mim ');
# Set password for root @ '2014. 0.0.1 '= password ('mim ');
# Flush privileges;
# Change master to master_host = 'master _ ip', master_user = 'username', master_password = 'mim ';
# Link master mysql
# Start slave;
# Show slave status;
Test
Create a database or table on the primary mysql instance to check whether mysql automatically copies the table.
 
The mode of the primary master is actually that both sides are master and slave at the same time. It can be simply understood as just integrating the master and slave configuration files ~~
One of the biggest problems in the master-master mode is that when both the master and slave write data to the same table at the same time, if the corresponding id is automatically increased, this is a serious problem, to solve this problem, you need to set different start values at the low end and specify the automatically added variable to 2.
 
 
 
Author: "residual snow"

Related Article

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.