当前位置:网站首页>Master slave replication configuration of MySQL
Master slave replication configuration of MySQL
2022-04-23 11:39:00 【you and me】
Abstract
Large projects pay special attention to backup , Generally, there is dual computer backup , Hot standby and cold standby , Remote disaster recovery and so on … Today, let's talk about... On two servers MySQL Master and slave copy backup , The requirements are simple : Slave data to be synchronized with master , But not too often , keep 15 Minutes of data difference , It means every 15 Minutes to synchronize once modified data .
Text
Our environment here is two Linux The server , One is on the public network , One is on the intranet , The public network is the master , Intranet is from , The databases are MySQL 5.7( Use LNMP install ).
Main warehouse operation
First, let's create a new data synchronization user , Let users use this from the library to synchronize data
CREATE USER 'slave'@'%' IDENTIFIED BY ' password ';
GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'slave'@'%';
The percent sign indicates that the user can use any number of IP Sign in .
Then we need to back up the main database , If your library is not accessed at this time , Then you don't have to lock the watch , But it's best to lock the table first and then back up
mysql> flush tables with read lock;
Use mysqldump Back up libraries that need to be synchronized , I'm syncing here mikublog This library
mysqldump -uroot -p --databases mikublog | gzip > mysql_bak.$(date + %F)sql.gz
After the backup, record the current location , remember File and Position Value
mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000014 | 154 | | | |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
Last unlock table
mysql> unlock tables;
Query OK, 0 rows affected (0.00 sec)
Operation from the library
Copy the compressed package just backed up , And extract the :gzip -d Compressed package name , And then put sql Brush it into the database .
modify my.cnf, Generally, you only need to change two values , hold server-id Change to unique value
[mysqld]
log-bin=mysql-slave-bin
server-id = 2
After the change, restart the database
service mysql restart
Set the master-slave configuration
mysql> change master to master_host='192.168.100.110', master_user='slave', master_password='mypassword', master_port=3306, master_log_file='mysql-bin.000014', master_log_pos= 154, master_delay=900, master_connect_retry=30;
Meaning of each parameter :
master_host : The address of the main library
master_port: The port number of the main library
master_user: Users for data synchronization
master_password: Password of the user for synchronization
master_log_file: Appoint Slave From which log file to start copying data , As mentioned above File Value of field
master_log_pos: From which Position Start reading , As mentioned above Position Value of field
master_delay: Delayed replication configuration , Set the delay from the database N Seconds later , And then synchronize with the master database
master_connect_retry: If the connection fails , Retry interval , The unit is seconds , The default is 60 second
Enable master-slave replication
mysql> start slave;
Query OK, 0 rows affected (0.00 sec)
View synchronization status
mysql> show slave status \G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
...
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
...
1 row in set (0.00 sec)
SlaveIORunning and SlaveSQLRunning All are Yes Indicates that master-slave replication has been turned on .
The end
That's all MySQL The content of the master-slave replication configuration , Welcome friends to exchange and discuss .
版权声明
本文为[you and me]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231136322971.html
边栏推荐
- nacos基础(6):nacos配置管理模型
- AcWing 1874. Moo encryption (enumeration, hash)
- Redis学习之五---高并发分布式锁实战
- nacos基础(7):配置管理
- Golang's pen test questions & interview questions 01
- Nacos Foundation (8): login management
- Redis optimization series (II) redis master-slave principle and master-slave common configuration
- Redis learning 5 - high concurrency distributed lock practice
- 远程访问家里的树莓派(上)
- Significance of actively participating in middle school robot competition
猜你喜欢

Nacos Foundation (7): Configuration Management

Application of remote integrated monitoring system in power distribution room in 10kV prefabricated cabin project

论坛系统数据库设计

Overall plan management mode in maker Education

Interpretation of biological recognition in robot programming course

解读机器人创造出来的艺术

nacos基础(6):nacos配置管理模型

Laravel绑定钉钉群警报(php)

全网最细的短网址系统设计与实战

SOFA Weekly | 年度优秀 Committer 、本周 Contributor、本周 QA
随机推荐
WIN10 启动后花屏
数据库如何填充IM表达式(IM 5.4)
nacos基础(8):登录管理
qt 64位静态版本显示gif
Write console script by laravel
少儿编程结构的改变之路
Tensorflow common functions
golang之笔试题&面试题01
kettle复制记录到结果和从结果获取记录使用
解读机器人创造出来的艺术
Share two practical shell scripts
云呐|如何管理好公司的固定资产,固定资产管理怎么做
map<QString, bool> 的使用记录
用户接口和IM表达式(IM 5.6)
Database design of simple voting system
Advanced file IO of system programming (13) -- IO multiplexing - Select
博客文章导航(实时更新)
激活函数之阶跃函数
IM表达式如何工作(5.3)
GPU, CUDA,cuDNN三者的關系總結