当前位置:网站首页>MySQL master-slave replication
MySQL master-slave replication
2022-06-26 00:07:00 【ZgaoYi】
1. Introduce
MySQL Master-slave replication is an asynchronous replication process , The bottom layer is based on Mysql Binary log function of database . Just one or more MySQL database (slave, From the library ) From the other AySQL database (master, The main library ) Copy the log, then parse the log and apply it to itself , Finally, the data of the slave database is consistent with that of the master database .MySQL Master slave replication is MySQL The database has its own functions , No third party tools required .
MySQL The replication process is divided into three steps :
- master Log changes to binary log (binary log)
- slave take master Of binary log Copy to its trunk log ( relay log)
- slave Redo events in relay log , Apply the changes to your own database

2. To configure
There is only one master database , Can be multiple from , This time, it is implemented on the virtual machine , Create two virtual machines , Equivalent to two servers , And install MySQL, Versions, . The implementation is as follows .
2.1 Main library Master
First step : modify Mysq1 Profile of the database /etc/my.cnf
vim /etc/my.cnf
add to :
log-bin=mysql-bin #[ must ] Enable binary logging
server-id=100 #[ must ] The server is unique ID
notes : there id Is the server IP The last number of , Such as my IP yes 192.168.125.100, here id Just fill in 100
The second step , Restart the database systemctl restart mysqld
The third step : Sign in Mysql database , Do the following SQL
GRANT REPLICATION SLAVE ON *.* to 'xiaoming'@'%' identified by 'Root@123456';
notes : above SQL The function of is to create a user xiaoming, The password for [email protected], And give xiaoming User grants REPLICATION SLAVE jurisdiction . It is often used to establish the user permissions required for replication , That is to say slave Must be master Authorize the user with this permission , Can be copied by this user .
Step four , Check the status , The next configuration circled here needs to be used when configuring from the database .
2.2 To configure - Slave Library Slave
First step : modify Mysql Profile of the database /etc/my.cnf
vim /etc/my.cnf
server-id=101 ##[ must ] The server is unique ID
The second step , Restart the database systemctl restart mysqld
The third step : Sign in Mysql database , Do the following SQL
change master to master_host =‘192.168.126.100’,master_user=‘xiaoming’,master_password=‘[email protected]’,master_log_file= ‘mysql-bin.000001’,master_log_pos=441;
If an error is reported slave Started , execute stop slave;
Then execute again
change master to master_host =‘192.168.126.100’,master_user=‘xiaoming’,master_password=‘[email protected]’,master_log_file= ‘mysql-bin.000001’,master_log_pos=441;
Restart after execution slave
start slave

3. Go to the database to test
In the main MySQL Add database to test1 , And then from MySQL Auto update add to test1
Configuration complete .
边栏推荐
猜你喜欢

我的博客今天2岁167天了,我领取了先锋博主徽章_过路老熊_新浪博客

Unable to start debugging. Unexpected GDB output from command “-environment -cd xxx“ No such file or

dhcp复习

SSM integrated learning notes (mainly ideas)

DNS复习

《网络是怎么样连接的》读书笔记 - 集线器、路由器和路由器(三)

Redis之内存淘汰机制

社交网络可视化第三方库igraph的安装

86.(cesium篇)cesium叠加面接收阴影效果(gltf模型)

10.4.1 data console
随机推荐
Record a simple question with ideas at the moment of brushing leetcode - Sword finger offer 09 Implementing queues with two stacks
Bit compressor [Blue Bridge Cup training]
正则表达式介绍及一些语法
Some common operation methods of array
详细讲解局部变量、全局变量、静态变量三种类型
《网络是怎么样连接的》读书笔记 - 集线器、路由器和路由器(三)
SSH review
Stop eating vitamin C tablets. These six fruits have the highest vitamin C content
常用的几款富文本编辑器
Smt贴片机工作流程
Realize the conversion between analog quantity value and engineering quantity value in STEP7_ Old bear passing by_ Sina blog
Literature research (I): hourly energy consumption prediction of office buildings based on integrated learning and energy consumption pattern classification
Connecting MySQL database with VBScript_ Old bear passing by_ Sina blog
86.(cesium篇)cesium叠加面接收阴影效果(gltf模型)
Shredding Company poj 1416
Search rotation array ii[Abstract dichotomy exercise]
About the solution to prompt modulenotfounderror: no module named'pymongo 'when running the scratch project
ValueError: color kwarg must have one color per data set. 9 data sets and 1 colors were provided
SPI锡膏检查机的作用及原理
Virtual and pure virtual destructors and their implementation in c++