当前位置:网站首页>MySQL master-slave replication solves read-write separation
MySQL master-slave replication solves read-write separation
2022-06-10 22:37:00 【Lingbeichen】
MySQL Master slave copy
The concept of separation of reading and writing
All the pressure of reading and writing is borne by one database , The data will be lost if the database service disk is damaged due to high pressure , A single point of failure

mysql Master-slave replication of can solve this problem
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 Mysql 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 Principal and subordinate malfeasance 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 his relay log (relay log)
slave Redo relay log events , Apply the changes to your own database

To configure - precondition
Prepare two servers in advance , Install separately mysql And start the service successfully
Main library master
First step : modify Mysql Profile of the database /etc/my.cnf
[mysqld]
log-bin=mysql-bin #[ must ] Enable binary logging
server-id=100 #[ must ] The server is unique ID
The second step : restart mysql service
systemctl restart mysqld
The third step : Sign in Mysql database , Do the following SQL
GRANT REPLICATION SLAVE ON *.* to 'xiaoming'@'%' identified by '[email protected]';
notes : above SQL The role of is to create a 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 : Sign in mysql data , Do the following SQL, Record the results File and Position Value
show master status;
notes : above SQL View when Master The state of , After that SQL Do not perform any more operations
Slave Library slave
First step : modify mysql Profile of the database /etc/my.cnf
[mysqld]
server-id=100 #[ must ] The server is unique ID
The second step : restart mysql service
systemctl restart mysqld
The third step : Sign in Mysql database , Do the following SQL
change master to master_host='192.168.138.100',master_user='xiaoming',master_password='[email protected]',master_log_file='mysql-bin.000001',master_log_pos=439;
start slave;
Step four : Sign in Mysql database , Do the following SQL, View the status of the slave database
show slave status;
The cause of the error
1. The Internet is not working 2. The password is wrong 3.pos incorrect 4. The firewall is not off 5.server-id Conflict
If you use clone virtual machines , Must be modified mysql Of uuid, Otherwise it will show Slave_IO_Running: No
terms of settlement :
1. First of all mysql Installation address of
show variables like 'datadir';
# adopt MySQL Generate a uuid Recording, etc. will be used to modify
select uuid
2. Then enter datadir Catalog
cd /var/lib/mysql/
vi auto.cnf
Take what you have just prepared uuid Value substitution
3. restart mysql
systemctl start mysqld
边栏推荐
- 记录(二)
- Latex error: file ‘xxx.sty‘ not found
- [py] the failure of interface signature verification may be due to ensure_ ASCII problems
- 【TcaplusDB知识库】TcaplusDB TcapDB扩缩容介绍
- [tcapulusdb knowledge base] Introduction to tcapulusdb patrol inspection statistics
- Ability to deliver packages within D days [abstract class dichotomy -- Abstract judgment method]
- (十一)TableView
- 【TcaplusDB知识库】TcaplusDB事务管理介绍
- TcaplusDB君 · 行业新闻汇编(一)
- What are MySQL clustered indexes and nonclustered indexes?
猜你喜欢

dc_labs--lab1的学习与总结

很流行的状态管理库 MobX 是怎么回事?

How to stimulate the vitality and driving force of cultural innovation

Differences between disk serial number, disk ID and volume serial number

(十一)TableView

What are MySQL clustered indexes and nonclustered indexes?

GMPNN:Drug-drug interaction prediction with learnable size-adaptive molecular substructures.

TcaplusDB君 · 行业新闻汇编(五)

leetcode 130. Surrounded regions (medium)

Matlab - 演化博弈论实现
随机推荐
Tcapulusdb Jun · industry news collection (I)
Simply Untyped Lambda Calculus的实现
What should I do if the mobile phone number cannot be updated
How small and micro enterprises build micro official websites at low cost
JVM runtime data area
[debug] could not find ref wiht POC XXX
【TcaplusDB知识库】TcaplusDB shard搬迁介绍
Shell基础概念
GMPNN:Drug-drug interaction prediction with learnable size-adaptive molecular substructures.
【TcaplusDB知识库】TcaplusDB事务管理介绍
Array plus one
README
按位操作符和移位操作符
TcaplusDB君 · 行业新闻汇编(三)
TypeScript - 声明文件和内置对象
[applet] the vant wearp radio radio radio component cannot trigger the bind:change event
SQL server queries are case sensitive
【TcaplusDB知识库】TcaplusDB日常巡检介绍
CCF CSP 202109-3 脉冲神经网络
Innovation and exploration are added layer by layer, and the field model of intelligent process mining tends to be mature