当前位置:网站首页>MySQL master-slave setup
MySQL master-slave setup
2022-07-19 03:33:00 【Doc_ ACwhite】
MYSQL The principle of master-slave :

1. First, you need two servers 【 Can work with colleagues / Build with friends 】
find mysql Edit and modify the configuration file of :( /etc/my.cnf)
Master database modification :
In the main warehouse mysqld This paragraph is added below
# The primary server is unique ID
server-id=1
# Enable binary logging
log-bin=mysql-bin
# Set up logbin Format
binlog_format=STATEMENT
# Set up the database not to be copied , You can set multiple
binlog-ignore-db=mysql
# Set up the database to be synchronized ( Database not created )
binlog-do-db=table1
#binlog-do-db After setting , You can leave it blank binlog-ignore-db
Exit and reload the configuration :
# heavy load mysql To configure
service mysqld restart
Get into mysql terminal , In the main warehouse mysql Register the account and password of the slave database on :
# Create a remote connection account password
GRANT REPLICATION SLAVE ON *.* TO 'slave_username'@'%' IDENTIFIED BY 'slave_password';
# Refresh mysql System permission related table
flush privileges;
# Check whether the establishment is complete
select user from mysql.user where user='slave_password';【slave_username Slave account ,slave_password Slave password 】

After configuration, you can check the configuration status of the main database
show master status;
- File:binlog The name of the Journal
- Position : Access point
- Binlog_Do_DB : The database that needs to be replicated
- Binlog_Ignore_DB : Databases that don't need to be replicated
- Executed_Gtid_Set: write in binlog Generated by logged transactions Gtid Set

Switch from server to server mysql To configure
stay mysqld Add this paragraph below ,
# The primary server is unique ID
server-id=2
# Enable relay logging
relay-log=mysql-relay
# Enable binary logging
log-bin=mysql-bin
Overload configuration :
show master status;
If master and slave have been configured , You need to restart the server before configuring
# Stop service from
stop slave;
# Reset master
reset master;

Then make the master-slave connection
CHANGE MASTER TO MASTER_HOST=' master server IP Address ', // The server ip Address
MASTER_USER=' Remote connection account ', //slave_username
MASTER_PASSWORD=' Remote connection password ', //slave_password
MASTER_LOG_FILE=' Main library binlog Log name ', //FIle
MASTER_LOG_POS= Main library access point ; //postion

Start the synchronization function after the master-slave connection is successful
# Turn on the synchronization function
start slave;
# View the slave library status
show slave status\G;


Be careful :Slave_IO_Running and Slave_SQL_Running The states of are Yes when , The configuration of slave database is successful .
Master slave test
(1)、 Create... On the master library jgyw Pattern , namely :
create schema jgyw;

(2)、 On the main library jgyw Create... In the pattern comm_config surface , namely :
use jgyw;
CREATE TABLE comm_config (configId varchar(200) NOT NULL ,configValue varchar(1024) DEFAULT NULL ,description varchar(2000) DEFAULT NULL ,PRIMARY KEY (configId)) ENGINE=InnoDB DEFAULT CHARSET=utf8 ;

(3)、 Go up the main warehouse comm_config Insert a record in the table , namely :
insert into comm_config(configId, configValue, description) values('name', ' Architecture and me ', ' Test it ');
(4)、 View the mode on the slave Library , namely :
show schemas;
The result is :
+--------------------+
| Database |
+--------------------+
| information_schema |
| jgyw |
| mysql |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.00 sec)
explain jgyw Mode synchronized to slave Library
(5)、 Check it out from the library jgyw Tables and data in mode , namely :
use jgyw;
show tables;
The result is :
+----------------+
| Tables_in_jgyw |
+----------------+
| comm_config |
+----------------+
1 row in set (0.00 sec)
The instruction table is synchronized , Look at the data , namely :
select * from comm_config;
The result is :
+----------+--------------+--------------+
| configId | configValue | description |
+----------+--------------+--------------+
| name | Architecture and me | Test it |
+----------+--------------+--------------+
1 row in set (0.00 sec)
It means that the data is synchronized .
边栏推荐
- 基于MFC如何实现单个文档的文件读写
- [NoSQL] redis configuration and optimization of NoSQL (simple operation)
- Chengxin University envi_ IDL second week class content: open hdf4 file and read the file, as well as simple data processing and saving + detailed analysis
- Dive Into Deep Learning——2.2数据预处理
- [Jianzhi offer] 31-35 questions (judge whether a sequence is one of the out of stack sequences, sequence print binary tree, branch print, and reverse print each line), judge whether the sequence is th
- CorelDRAW cannot be installed. Solution
- Dqn theoretical basis and code implementation [pytoch + cartpole-v0]
- 洛谷每日三题之第三天(第四天补做)
- Win10 onedrive failure reinstallation
- 支持工业级瘦设备4G接入,润和软件DAYU120通过OpenHarmony兼容性测评
猜你喜欢

leetcode:50. Pow(x, n)
![Theoretical basis of double Q-learning and its code implementation [pendulum-v0]](/img/f4/d281bf9e0534aed1d802d32ac35782.png)
Theoretical basis of double Q-learning and its code implementation [pendulum-v0]

MySQL optimized index

Comparison between redis and other databases

通过OpenHarmony兼容性测评,大师兄开发板与丰富教培资源已ready

Simple usage and interface introduction of labelme

MySQL multi table query

ES6 learning notes - brother Ma at station B

Chengxin University envi_ The second week of IDL experiment content: extract aod+ in all MODIS aerosol products for detailed analysis

基于MFC如何实现单个文档的文件读写
随机推荐
Browser cannot open tensorboard
基于MFC如何实现单个文档的文件读写
Rhce8 Learning Guide Chapter 1 installing rhel8.4
[NoSQL] redis configuration and optimization of NoSQL (simple operation)
05 central processing unit
Backup kubernetes backup etcd data
Win10 network connection shows no network but Internet access
谷歌 Chrome 浏览器安装 PWA 应用将显示更多描述信息
Ubuntu clear CUDA cache
Chengxin University envi_ IDL second week homework: extract aerosol thickness at n points + detailed analysis
Chengxin University envi_ The second week of IDL experiment content: extract aod+ in all MODIS aerosol products for detailed analysis
Dive Into Deep Learning——2.2数据预处理
Dive into deep learning - 2.2 data preprocessing
Gdb+vscode for debugging 8 - use core to analyze dead cycles, deadlocks, and segment errors
Replacement operation not supported by ncnn partial operators
Chengxin University envi_ IDL second week class content: open hdf4 file and read the file, as well as simple data processing and saving + detailed analysis
論文閱讀:U-Net++: Redesigning Skip Connections to Exploit Multiscale Features in Image Segmentation
Zabbix6.0 monitoring vcenter7.0
Go语言中的Iota关键字怎么使用
We should increase revenue and reduce expenditure