当前位置:网站首页>mysql 主从复制
mysql 主从复制
2022-06-25 22:12:00 【ZgaoYi】
1.介绍
MySQL主从复制是一个异步的复制过程,底层是基于Mysql数据库自带的二进制日志功能。就是一台或多台MySQL数据库(slave,即从库)从另一台AySQL数据库(master,即主库)进行日志的复制然后再解析日志并应用到自身,最终实现从库的数据和主库的数据保持一致。MySQL主从复制是MySQL数据库自带功能,无需借助第三方工具。
MySQL复制过程分成三步:
- master将改变记录到二进制日志(binary log)
- slave将master的binary log拷贝到它的中继日志( relay log)
- slave重做中继日志中的事件,将改变应用到自己的数据库中

2.配置
主数据库只有一个,从可以多个,本次是在虚拟机上实现,创建两个虚拟机,相当于两个服务器,并安装好MySQL,版本一致。实现如下。
2.1 主库Master
第一步:修改Mysq1数据库的配置文件/etc/my.cnf
vim /etc/my.cnf
添加:
log-bin=mysql-bin #[必须]启用二进制日志
server-id=100 #[必须]服务器唯一ID
注:这里的id是服务器IP的尾数字,比如我的IP是192.168.125.100,这里id就填100
第二步,重启数据库 systemctl restart mysqld
第三步:登录Mysql数据库,执行下面SQL
GRANT REPLICATION SLAVE ON *.* to 'xiaoming'@'%' identified by 'Root@123456';
注:上面SQL的作用是创建一个用户xiaoming,密码为[email protected],并且给xiaoming用户授予REPLICATION SLAVE权限。常用于建立复制时所需要用到的用户权限,也就是slave必须被master授权具有该权限的用户,才能通过该用户复制。
第四步,查看状态,这里圈出的后边配置从数据库时需要用到。
2.2 配置-从库Slave
第一步:修改Mysql数据库的配置文件/etc/my.cnf
vim /etc/my.cnf
server-id=101 ##[必须]服务器唯一ID
第二步,重启数据库 systemctl restart mysqld
第三步:登录Mysql数据库,执行下面SQL
change master to master_host =‘192.168.126.100’,master_user=‘xiaoming’,master_password=‘[email protected]’,master_log_file= ‘mysql-bin.000001’,master_log_pos=441;
如果出现报错slave已启动,则执行stop slave;
然后重新执行
change master to master_host =‘192.168.126.100’,master_user=‘xiaoming’,master_password=‘[email protected]’,master_log_file= ‘mysql-bin.000001’,master_log_pos=441;
执行完重新开启slave
start slave

3.去数据库测试一下
在主MySQL中添加数据库test1 ,然后从MySQL 自动更新 添加test1
配置完成。
边栏推荐
- 西门子S7-200PLC和丹佛斯变频器的通讯协议改造_过路老熊_新浪博客
- 7.常用指令(下)v-on,v-bind,v-model的常见操作
- How postman tests interfaces that require login
- Simulation connection between WinCC and STEP7_ Old bear passing by_ Sina blog
- 6.常用指令(上)v-cloak,v-once,v-pre
- [wechat official account H5] generates a QR code with parameters to enter the official account attention page to listen to user-defined menu bar for official account events (server)
- 手工制作 pl-2303hx 的USB转TTL电平串口的电路_过路老熊_新浪博客
- Format the number. If the number is not enough, fill in 0, for example, 1:0001,25:0025
- InputStream流已经关闭了,但是依旧无法delete文件或者文件夹,提示被JVM占用等
- Circuit de fabrication manuelle d'un port série de niveau USB à TTL pour PL - 2303hx Old bear passing Sina blog
猜你喜欢

今天说说String相关知识点

Unable to start debugging. Unexpected GDB output from command “-environment -cd xxx“ No such file or
![[wechat official account H5] generates a QR code with parameters to enter the official account attention page to listen to user-defined menu bar for official account events (server)](/img/d9/935bad29005e5846dc514c966e3b0e.png)
[wechat official account H5] generates a QR code with parameters to enter the official account attention page to listen to user-defined menu bar for official account events (server)

Recherche documentaire (3): examen des modèles de prévision de la consommation d'énergie des bâtiments fondés sur les données

Unsigned and signed vernacular

Common problems encountered when creating and publishing packages using NPM

手工制作 pl-2303hx 的USB轉TTL電平串口的電路_過路老熊_新浪博客

About Simple Data Visualization

Literature research (IV): Hourly building power consumption prediction based on case-based reasoning, Ann and PCA

Circuit de fabrication manuelle d'un port série de niveau USB à TTL pour PL - 2303hx Old bear passing Sina blog
随机推荐
Lazy people teach you to use kiwi fruit to lose 16 kg in a month_ Old bear passing by_ Sina blog
Tensorflow中CSV文件数据读取
Problems encountered in Doris operation and maintenance
Apache Doris1.0版本集群搭建、负载均衡与参数调优
About the swoole coroutine container
huibian
Redis之跳跃表
Mutual conversion of float type data and datetime type data in sqlserver2008
Talk about how to hot restart a spoole or PHP cli process
Unsigned and signed vernacular
Redis之常见问题
Given the parameter n, there will be n integers 1, 2, 3,... From 1 to n, n. These n arrays have n! An arrangement that lists all columns in ascending order of size and marks them one by one. Given n a
The role of iomanip header file in actual combat
Doris 运维中遇到的问题
Linking MySQL database with visual studio2015 under win10
JS中的原型链面试题--Foo和 getName
Find the minimum value of flipped array [Abstract bisection]
使用npm创建并发布包时遇到的常见问题
SSM integrated learning notes (mainly ideas)
Oracle writes a trigger that inserts a piece of data first and updates a field in the data