当前位置:网站首页>MySQL practice -- master-slave replication
MySQL practice -- master-slave replication
2022-07-28 13:17:00 【daydreamed】
MySQL Practice chapter —— Master slave copy
1、 summary
Master slave copy Namely hold master server (Master) Upper Binary log file (binlog, All operations to modify the database are recorded ) Copied to the From the server (Slave) Last execution , Guarantee From the server The data on the and master server The data on the bring into correspondence with .
working process :
- master server Change data It was recorded that Binary log file in
- From the server To start a I/O Threads adopt MySQL agreement hold master server Of Binary log file Copy to your own Relay log file (relay log) in
- From the server To start a SQL Threads perform Relay log file The content in
Add :I/O Threads and SQL Threads
- I/O Threads : Responsible for reading Binary log file of the primary server , And save it as Relay log file
- SQL Threads : perform Relay log file The content in

2、 practice
1、 stay E disc establish master and slave Catalog
2、 Find this machine MySQL The installation path take Overall folder Compress and pack
3、 take Compressed package Copy them to master and slave Under the table of contents , And finish decompressing
4、 To configure MySQL System files for my.ini
master Of my.ini To configure
use Notepad ( Or other editors ) open master root directory Under the my.ini, stay [mysqld] Next newly added
log-bin=mysql-bin server-id=3306and Keep close .[mysqld] log-bin=mysql-bin # Indicates the name of the binary log file to be generated server-id=3306slave Of my.ini To configure
use Notepad ( Or other editors ) open slave root directory Under the my.ini, take [client] Next Of port( Port number ) from 3306 Change to 3307; take [mysqld] Next Of port from 3306 Change to 3307, newly added
log-bin=mysql-bin server-id=3307and Keep close .[mysqld] log-bin=mysql-bin server-id=3307 port=3307 [client] port=3307
5、 start-up master The server , And create an account specifically for replication
Open command window cmd, Get into master Of bin Catalog , Enter the command to start the server :
mysqld --console, Start the serverOpen command window cmd, Get into master Of bin Catalog , Input
mysql -u root -p, Log in to master The serverestablish Copy accounts , user name repuser, password 123
mysql>Create user 'repuser'@'localhost' identified by '123'; mysql>grant replication slave on *.* to 'repuser'@'localhost'; mysql>flush privileges; mysql>show master status \G # Show master state ; \G Display in rows , Don't add it in the back ';'


6、 start-up slave The server , complete slave Configuration of
Open command window cmd, Get into slave Of bin Catalog , Enter the command to start the server :
mysqld --console, Start the serverOpen command window cmd, Get into slave Of bin Catalog , Input
mysql -u root -pLog in to slave The servercomplete Master slave copy Related configuration of
mysql>change master to master_host='localhost',master_port=3306,master='repuser',master_password='123',master_log_file='mysql-bin.000001',mastet_log_pos=0;start-up slave and Check its status
mysql>start slave; mysql>show slave status \G


notes : Check Slave_IO_Running Threads and Slave_SQL_Running Threads Is it all for yes, If it is , Express Master slave replication service Established ; If not , Express Master slave replication service Not established .
7、 Master slave replication test
(1) stay master client , Create a database BankDB, Once created , stay slave client Check whether there is BankDB:show databases;
DROP SCHEMA IF EXISTS BankDB ;
CREATE SCHEMA IF NOT EXISTS BankDB default character set gbk;
USE BankDB;
Create table Bank(BankID int, Cname char(20), Balance decimal(10,2));
insert into Bank values (20181211,' Zhang San ', 20000);
insert into Bank values (20181212,' Li Si ', 10000);
insert into Bank values (20181213,' Wang Wu ', 20000);
master client :

slave client :

(2) stay master client , modify Bank The data table , stay slave client Check whether the update is successful
update Bank set Balance=Balance + 99;
master client :

slaver client :

(3) stay slave Closed (slave client :stop slave,slave Server side :Ctrl+C), stay master client Create a new database BankDB1; Restart slave, stay slave client Check whether the newly created database appears BankDB1
DROP SCHEMA IF EXISTS BankDB1;
CREATE SCHEMA IF NOT EXISTS BankDB1 default character set gbk;
USE BankDB1;
Create table Bank(BankID int, Cname char(20), Balance decimal(10,2));
insert into Bank values (20181211,' Zhang San ', 20000);
insert into Bank values (20181212,' Li Si ', 10000);
insert into Bank values (20181213,' Wang Wu ', 20000);
master client :

slaver client :



边栏推荐
- Transaction of MySQL underlying principle (2)
- PCP parity principle arbitrage
- [embedded C foundation] Part 5: original code / inverse code / complement code
- Redis —— 基础篇
- 2020-12-07
- Summary: idea problem record
- What if the win11 folder cannot be opened
- Ruan Bonan of Green Alliance Technology: cloud native security from the open source shooting range
- GameStop熊市杀入NFT交易,老牌游戏零售商借Web3焕发第二春
- [matlab]: FFT related problems
猜你喜欢

Original juice multifunctional Juicer touch chip-dlt8t02s-jericho

【嵌入式C基础】第1篇:基本数据类型

Change password, confirm password verification antd

Leetcode daily question (2196. create binary tree from descriptions)

UV germicidal lamp chip dlt8p65sa Jericho

Margin calculation

Understanding of vite2

【嵌入式C基础】第6篇:超详细的常用的输入输出函数讲解

黑猫带你学eMMC协议第24篇:eMMC的总线测试程序详解(CMD19 & CMD14)

Machine learning Basics - decision tree-12
随机推荐
Fundamentals of machine learning Bayesian analysis-14
Transaction of MySQL underlying principle (2)
Xampp Chinese tutorial guide
[embedded C foundation] Part 4: use of operators
Automatic light sensing arm lamp touch chip-dlt8sa15b-jericho
[graduation design] oscilloscope design and Implementation Based on STM32 - single chip microcomputer Internet of things
LeetCode每日一题(2196. Create Binary Tree From Descriptions)
Vditor 渲染器如何做到服务端渲染(SSR)?
[error prone points of C language] Part 4: detailed rules for storing structures in memory
【嵌入式C基础】第9篇:C语言指针的基本用法
Installation and reinstallation of win11 system graphic version tutorial
QT signal and slot mechanism (detailed)
Qt 信号和槽机制( 详解 )
Protobuf data exchange format
Ruan Bonan of Green Alliance Technology: cloud native security from the open source shooting range
JVM 内存管理 你知道多少
2020-12-13
Introduction to border border attribute
拥有游戏的一部分,写在我的世界禁用NFT之后
[embedded explanation] key scanning based on finite state machine and stm32