当前位置:网站首页>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 :



边栏推荐
- [embedded C foundation] Part 5: original code / inverse code / complement code
- 【嵌入式C基础】第8篇:C语言数组讲解
- Risk analysis of option trading
- The difference between sessionstorage, localstorage and cookies
- BiliBili Yang Zhou: above efficiency, efficient delivery
- CTO of youhaoda, MVP of Huawei cloud, and Zhang Shanyou: build cloud native applications based on kubernetes and dapr
- 【嵌入式C基础】第1篇:基本数据类型
- Compare the new and old data to find the added and deleted ones
- [embedded C foundation] Part 8: explanation of C language array
- Summary: golang's ide:vscode usage
猜你喜欢

butterfly spreads
![[embedded C foundation] Part 1: basic data types](/img/45/b0bc9e90b0582f0f2624ce27b5a76c.png)
[embedded C foundation] Part 1: basic data types
![[basic teaching of Bi design] detailed explanation of OLED screen use - single chip microcomputer Internet of things](/img/76/820d4e357206f936b33da92a5e2b5b.png)
[basic teaching of Bi design] detailed explanation of OLED screen use - single chip microcomputer Internet of things
![[FPGA] FIR filter - half band filter](/img/6e/d97b3842f80e37aa41b888384a14cb.png)
[FPGA] FIR filter - half band filter

Introduction to border border attribute

Dimming and color matching cool light touch chip-dlt8ma12ts-jericho

Analysis of Andriod low on memory printing principle

2020-12-27

夜神模拟器抓包微信小程序

LeetCode每日一题(2196. Create Binary Tree From Descriptions)
随机推荐
Definition of option basis
Summary: golang's ide:vscode usage
Use and source code of livedata in jetpack family bucket
Is jetpack compose completely out of view?
Datanode data block missing problem finding
CTO of youhaoda, MVP of Huawei cloud, and Zhang Shanyou: build cloud native applications based on kubernetes and dapr
【嵌入式C基础】第6篇:超详细的常用的输入输出函数讲解
Tidb 6.x in action was released, a summary of 6.x practices that condense the collective wisdom of the community!
Redis —— 基础篇
How to add PDF virtual printer in win11
Compare the new and old data to find the added and deleted ones
RGB game atmosphere light touch chip-dlt8s04a-jericho
How many times can the WordPress user name be changed? Attach the method of changing user name
Transaction of MySQL underlying principle (2)
Chapter 6 提升
Extended operator
【嵌入式C基础】第7篇:C语言流程控制详讲
Smart touch screen LCD bathroom mirror light touch chip-dlt8t02s-jericho
How to open the power saving mode of win11 system computer
如何在 TiDB Cloud 上使用 Databricks 进行数据分析 | TiDB Cloud 使用指南