当前位置:网站首页>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
边栏推荐
- 远程访问家里的树莓派(上)
- Tclerror: no display name and no $display environment variable
- 解决由于找不到amd_ags_x64.dll,无法继续执行代码。重新安装程序可能会解决此问题,地平线(Forza Horizon 5)
- RebbitMQ的初步了解
- thinkphp 添加图片文字水印生成带二维码的推广海报
- My creation anniversary
- Tensorflow使用keras创建神经网络的方法
- Using Baidu PaddlePaddle EasyDL to accomplish specified target recognition
- Redis optimization series (II) redis master-slave principle and master-slave common configuration
- 第四章 为物化视图启用和禁用IM列存储(IM 4.6)
猜你喜欢

实践数据湖iceberg 第三十课 mysql->iceberg,不同客户端有时区问题

Laravel adds custom helper functions

Share two practical shell scripts

激活函数之sigmoid函数

创客教育中的统筹方案管理模式

云呐|如何管理好公司的固定资产,固定资产管理怎么做

分享两个实用的shell脚本

一文详解头部位姿估计【收藏好文】

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

Simple construction of rebbitmq
随机推荐
Laravel admin time range selector daterange default value problem
Nacos Basics (5): getting started with Nacos configuration
map<QString, bool> 的使用记录
Significance of actively participating in middle school robot competition
Application of remote integrated monitoring system in power distribution room in 10kV prefabricated cabin project
力扣-1137.第N个泰波那契数
云呐|固定资产盘点中,支持多种盘点方式(资产清查盘点)
系统编程之高级文件IO(十三)——IO多路复用-select
Yunna | how to manage the company's fixed assets and how to manage fixed assets
nacos基础(9):nacos配置管理之从单体架构到微服务
PCB的注意事项
MQ在laravel中简单使用
oh-my-lotto
分享两个实用的shell脚本
Database design of forum system
golang之筆試題&面試題01
项目实训-火爆辣椒
On the integration of steam education in early childhood education
Overall plan management mode in maker Education
PSCP 基本使用