当前位置:网站首页>MySQL master-slave replication
MySQL master-slave replication
2022-06-24 12:52:00 【User 1168904】
1. The system versions are rhel5 mysql Same version
2. The primary server is running , Can't stop .
3. master server IP by :192.168.1.100
From the server IP by :192.168.1.101
4. From the server MSYQL slave It is in the stop state
Configuration steps :
1、 Main library creation /etc/my.cnf, modify [mysqld] The key value inside is increased
server-id=1
log-bin=binlog_name
2、 Add user to main library , Used to read the main library log from the library .
grant replication slave,reload,super on *.* to'slave'@'192.168.1.101'identified by '123456';
flush privileges;
3、 Connect from the library to the main library for testing .
mysql -u slave -p -h 192.168.1.100 //master Of IP
4、 Stop from library , Modify slave Library /etc/my.cnf, Add options :
[mysqld]
server-id=2
master-host=192.168.1.100
master-user=slave
master-password=123456
5. Lock table
mysql > FLUSH TABLES WITH READ LOCK;
Be careful : In order to ensure FLUSH TABLES Statement to keep the read lock in effect .( If you exit the client program , The lock is released ). Set up new SSH Connect , Then, the data on the primary server is processed quickly
mirror .
6. Take a snapshot
tar -cvf data.tar /var/lib/mysql
Copy the compressed package and decompress it
It can also be used. scp Copy the past :
scp -r /var/lib/mysql/* 192.168.1.101:/var/lib/mysql/
Pay attention to the permission settings after copying
chown -R mysql.mysql /var/lib/mysql
A large amount of data can be used mysqldump export .
7. Unlock
mysql > UNLOCK TABLES;
8. Write down the file pos value
When FLUSH TABLES WITH READ LOCK When the set read lock is valid , Read the current binary log name on the primary server (file) And offset values (pos):
mysql > SHOW MASTER STATUS;
+---------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+---------------+----------+--------------+------------------+
| mysql-bin.003 | 73 | test | manual,mysql |
+---------------+----------+--------------+------------------+
File The column displays the log name , and Position Display offset . In this example , The binary log value is mysql-bin.003, The offset for the 73. Record the value . You need to set up the slave server in the future
Use these values . They represent duplicate coordinates , The slave server should start from this point ( It can also be any point ) Start a new update from the primary server .
9. Perform synchronization from the server
# mysql>start slave;
# mysql>load data from master;
10. Verify configuration
Log in and input the following command from the server :
mysql> show slave status\G;
You will get a list similar to the following :
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
All for yes, The configuration is correct .
11. To test :
Main database create table ,
mysql>create database sampdb;
mysql>use sampdb;
mysql>create table new (name char(20),phone char(20));
mysql>insert into new (’abc‘,’0532555555’);
The master and slave servers are restarted ;
Open from library , see :
#mysql -u root -p
mysql>show databases; // You should be able to see master Created library sampdb
mysql
sampdb
test
mysql>use sampdb;
mysql>show tables;
new
This indicates that the master-slave database is successfully created .
attach :
Some error information processing , Commands on master and slave servers , And status information .
Use... On the slave server show slave status\G
Slave_IO_Running, by No,
shows IO_THREAD Has not started , Please perform start slave io_thread
Slave_SQL_Running by No
Copy error , see Last_error After the field eliminates the error, execute start slave sql_thread
see Slave_IO_State Field empty // Replication did not start
Connecting to master// Not connected maste
Waiting for master to send event// It's connected to
Related commands on the master server :
show master status
show slave hosts
show logs
show binlog events
purge logs to 'log_name'
purge logs before 'date'
reset master( The old version flush master)
set sql_log_bin=
From the relevant commands on the server :
slave start
slave stop
SLAVE STOP IO_THREAD // This thread puts master The log of segment is written to local
SLAVE start IO_THREAD
SLAVE STOP SQL_THREAD // This thread applies logs written locally to the database
SLAVE start SQL_THREAD
reset slave
SET GLOBAL SQL_SLAVE_SKIP_COUNTER
load data from maste
show slave status(SUPER,REPLICATION CLIENT)
CHANGE MASTER TO MASTER_HOST=, MASTER_PORT=,MASTER_USER=, MASTER_PASSWORD= // The dynamic change master Information
PURGE MASTER [before 'date'] Delete master The logs that have been synchronized at the end
Several related to hot standby mysql command :( Need to be in mysql Command line interface or query )
* stop slave # Stop syncing
* start slave # Start syncing , Update from the end of the log .
* SET SQL_LOG_BIN=0|1 # The host side runs , need super jurisdiction , Used to start and stop the log , Random start and stop , This will cause inconsistency between host and slave data , Cause mistakes
* SET GLOBAL SQL_SLAVE_SKIP_COUNTER=n # Client running , Used to skip several events , Only when the synchronization process stops due to an error can it be executed .
* RESET MASTER # The host side runs , Clear all logs , This command is the original FLUSH MASTER
* RESET SLAVE # Slave operation , Clear the log synchronization location flag , And regenerate master.info
Although regenerated master.info, But it doesn't work , best , Will be driven from mysql Restart the process ,
* LOAD TABLE tblname FROM MASTER # Slave operation , Reread the data of the specified table from the host , Only one... Can be read at a time , suffer timeout The time limit , Need to adjust timeout Time . To execute this command, you need to synchronize the accounts reload and super jurisdiction . And the corresponding library has select jurisdiction . If the watch is bigger , To increase net_read_timeout and net_write_timeout Value
* LOAD DATA FROM MASTER # Slave execution , Re read all data from the host . To execute this command, you need to synchronize the accounts reload and super jurisdiction . And the corresponding library has select jurisdiction . If the watch is bigger , To increase net_read_timeout and net_write_timeout Value
* CHANGE MASTER TO master_def_list # Change some host settings online , Multiple are separated by commas , such as
CHANGE MASTER TO
MASTER_HOST='master2.mycompany.com',
MASTER_USER='replication',
MASTER_PASSWORD='bigs3cret'
* MASTER_POS_WAIT() # Slave operation
* SHOW MASTER STATUS # Host running , See the log export information
* SHOW SLAVE HOSTS # Host running , Look at the connected slave .
* SHOW SLAVE STATUS (slave)
* SHOW MASTER LOGS (master)
* SHOW BINLOG EVENTS [ IN 'logname' ] [ FROM pos ] [ LIMIT [offset,] rows ]
* PURGE [MASTER] LOGS TO 'logname' ; PURGE [MASTER] LOGS BEFORE 'date'
边栏推荐
- Fbnet/fbnetv2/fbnetv3: Facebook's lightweight network exploration in NAS | lightweight network
- [tke] GPU node NVIDIA Tesla driver reinstallation
- SMS SMS
- Generate the NC file of 4-D air pressure and temperature, and then read the code (provide the code)
- 105. simple chat room 8: use socket to transfer pictures
- Istio Troubleshooting: uneven grpc service load
- Attack Science: DDoS (Part 2)
- Design and implementation of high performance go log library zap
- Use terminal to activate CONDA service in pypharm (the ultimate method is definitely OK)
- What is the reason why the video intelligent analysis platform easycvr is locally controllable but the superior equipment cannot control the subordinate equipment?
猜你喜欢

openGauss内核:简单查询的执行

About the hacked database

《回归故里》阅读笔记

Use terminal to activate CONDA service in pypharm (the ultimate method is definitely OK)

手把手教你用AirtestIDE无线连接手机!

文本转语音功能上线,可以体验专业播音员的服务,诚邀试用

简述聚类分析

WPF from zero to 1 tutorial details, suitable for novices on the road

Who said that "programmers are useless without computers? The big brother around me disagrees! It's true
![[database] final review (planning Edition)](/img/94/cd2df3a011c4e466df5aaa0f3bd0f2.png)
[database] final review (planning Edition)
随机推荐
Google hacking search engine attack and Prevention
Encapsulate the method of converting a picture file object to Base64
Brief introduction to cluster analysis
“有趣” 是新时代的竞争力
Automatic reconstruction of pod after modifying resource object
Implement Domain Driven Design - use ABP framework - create entities
Simple and flexible permission design?
It's settled! Bank retail credit risk control just does it!
Use txvideoeditor to add watermark and export video card at 99%? No successful failed callback?
Five minutes to develop your own code generator
How does the video networking / network penetration tool easynts permanently delete one of the devices?
RTMP streaming platform easydss video on demand interface search bar development label fuzzy query process introduction
IOMMU (VII) -vfio and mdev
Dingding, Feishu, and enterprise wechat: different business approaches
Kubernetes practical skills: use cert manager to issue free certificates for DNSPod domain names
Another prize! Tencent Youtu won the leading scientific and technological achievement award of the 2021 digital Expo
从《梦华录》的争议性,谈谈数字版权作品的价值泡沫
一文讲透植物内生菌研究怎么做 | 微生物专题
短信服务sms
Istio practical skills: using prism to construct multi version test services