In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
In this issue, the editor will bring you about the principle analysis of MySQL master-slave replication. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.
I. basic principles
The MySQL replication process is divided into three steps:
1), master records the changes to the binary log (binary log). These recording processes are called binary log events, binary log events
2), slave copies the binary log events of master to its relay log (relay log)
3) slave redo the events in the relay log and apply the changes to its own database. MySQL replication is asynchronous and serialized.
To put it simply: slave reads binlog from master for data synchronization
The replication of MySQL is an asynchronous replication.
The whole replication operation is mainly completed by three processes, two of which are on Slave (Sql process and IO process), and the other is on Master (IO process).
To implement replication, you must first turn on the binary log (bin-log) function on the Masterside, otherwise it cannot be implemented.
Because the whole replication process is actually Slave takes the log from the Master side and then performs the various operations recorded in the log in full sequence on its own.
The detailed process of replication:
(1) the IO process on the Slave connects to the Master and requests the log contents from the specified location of the specified log file (or from the beginning of the log)
(2) after Master receives the request from the IO process of Slave, the IO process responsible for replication reads the log information after the specified location of the log according to the request information, and returns it to the IO process of Slave. In addition to the information contained in the log, the returned information also includes the name of the bin-log file that has been sent to Master and the location of the bin-log.
(3) after receiving the information, the IO process of Slave adds the received log content to the end of the relay-log file on the server, and records the file name and location of the read bin-log on the Masterside into the master-info file, so that it can clearly read the high-speed Master the next time it is read. "where do I need to start the log content in a certain bin-log, please send it to me"
(4) after the Sql process of Slave detects the newly added content in relay-log, it will immediately parse the content of relay-log into those executable contents that are actually executed on the Masterside and execute in itself.
Principles:
There is only one master per slave
There can be only one unique server ID per slave
Each master can have multiple salve
Second, one master and one slave related configuration
Demo host is Windows (configuration file is my.ini file) and slave is Linux (configuration file is my.cnf)
1. Host configuration (my.ini of windows)
1), [must] the master server has a unique ID
2), [must] enable binary log; log-bin= 's own local path / data/mysqlbin. Log-bin=D:/devSoft/MySQLServer5.5/data/mysqlbin .
3), [optional] enable the local path / data/mysqlerr of the error log log-err=. Log-err=D:/devSoft/MySQLServer5.5/data/mysqlerr .
4), [optional] root directory basedir= "own local path". Basedir= "D:/devSoft/MySQLServer5.5/".
5), [optional] temporary directory tmpdir= "own local path". Tmpdir= "D:/devSoft/MySQLServer5.5/".
6), [optional] data directory datadir= "own local path / Data/". Datadir= "D:/devSoft/MySQLServer5.5/Data/".
7), [optional] set the database binlog-ignore-db=mysql that should not be replicated.
8), [optional] set the name of the master database that needs to be replicated for the database to be replicated by binlog-do-db=.
2. Slave configuration (my.cnf of linux)
[must] unique ID from the server
[optional] enable binary logging
3. Because the configuration file has been modified, ask the host and slave to restart the background mysql service. 4. Turn off the linux firewall for both the master and slave.
Windows shuts down manually
Turn off virtual machine linux Firewall service iptables stop
5. Establish an account on the Windows host and authorize slave
GRANT REPLICATION SLAVE ON *. * TO 'zhangsan'@' from the machine database IP' IDENTIFIED BY' 123456;.
Refresh the configuration flush privileges;.
Query the status of master. Show master status; records the values of File and Position
After performing this step, do not manipulate the primary server MYSQL to prevent the primary server status value from changing.
6. Configure the host to be replicated on the Linux slave
Configuration
CHANGE MASTER TO MASTER_HOST=' host IP',MASTER_USER='zhangsan',MASTER_PASSWORD='123456',MASTER_LOG_FILE='File name', MASTER_LOG_POS=Position number
Start the copy from server function, start slave;.
If you check the configuration, the following two parameters are both Yes, which means the master-slave configuration is successful! Slave_IO_Running: Yes . Slave_SQL_Running: Yes .
CHANGE MASTER TO MASTER_HOST='192.168.124.3', MASTER_USER='zhangsan', MASTER_PASSWORD='123456', MASTER_LOG_FILE='mysqlbin. Specific number', specific value of MASTER_LOG_POS=
7. Master key table to see if the slave machine has 8. How to stop the master-slave service replication function
Enter stop slave; under linux.
The above is the editor for you to share the principle of MySQL master-slave copy analysis is how, if you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.