当前位置:网站首页>sql主從複制搭建
sql主從複制搭建
2022-06-28 07:52:00 【Fairy要carry】
目錄
mysql主從介紹

mysql從機複制的步驟:
slave會從master讀取binlog來進行數據同步
1 master主機將改變記錄到二進制日志(binary log)。這些記錄過程叫做二進制日志事件,binary log events;
2 slave將master的binary log events拷貝到它的中繼日志(relay log);
3 slave重做中繼日志中的事件,將改變應用到自己的數據庫中。 MySQL複制是异步的且串行化的
幾種處理模式:

statement模式:不能使用函數,比如說你的主機使用函數now()記錄時間但是當同步到從機的時候,他的時間就會發生變化(明顯不一致),從而導致主從複制數據不一致的情况發送(個人感覺有點像RDB,直接數據同步,會有數據不一致情况);
行模式row:效率較低,記錄每一行的改變,如果數據量達到一個層面就會很慢了(個人感覺有點像AOF,給從機每一行去執行);
MIXED模式:前面兩種模式的結合版本;
主從搭建
修改主機的配置文件:
先找到主機mysql的配置文件my.ini,然後配置日志文件的目錄與設置不需要複制的數據庫和需要複制的數據庫名字


然後對從機的配置文件修改:
對my.cnf文件修改

1.在主機中創建一個用戶,對於本機數據庫中有所有權限
#在主機本地,給遠程賦予權限
GRANT REPLICATION SLAVE ON *.* TO 'slave190401'@'%' IDENTIFIED BY '123';

查看主機數據庫狀態
show master status 
2.重啟mysql主機

3.然後在linux下重啟我們的mysql從機
systemctl restart mysqld
4.然後我們查看一下mysql的status,發現running active即可
systemctl status mysqld
5.然後在window下關閉所有的防火牆
並且關閉linux下的防火牆stop
systemctl status firewalld
mysql的主從複制和redis那些是有點相像的
從機訪問主機的Binary log都需要進行驗證,看能不能進行訪問,而我們的redis集群從機訪問主機(也就是得到主機的RDB、AOF文件),也需要進行驗證看是不是第一次數據加載,而這個驗證就是看的id是不是相同的
Binlog_Do_DB和Binlog_Ignore_DB指的是要複制的數據庫和不要複制的數據庫
此時主機不要對這個Bin_Do_DB數據庫進行操作,這是主從的數據庫,如果變更,Position就會發送改變

6.此時我們需要對linux下的mysql進行操作:拜主機為大哥,跟slave of有點相像
CHANGE MASTER TO MASTER_HOST='192.168.184.1',
MASTER_USER='slave190401',
MASTER_PASSWORD='123',
MASTER_LOG_FILE='mysqlbin.000001',MASTER_LOG_POS=107;
7.如果之前從機給主機拜大哥出現問題,需要reset一下
stop slavereset master然後我們再開啟主從複制
start slave8.查看從機狀態(類似redis中的 info replication)
show slave status\G
對主機數據庫進行操作
對主機進行操作創建mydb_190401數據庫後,發現我們從機用戶連接的數據庫也有了
有延遲,毫秒級,完美bro

如果說你從機拜大哥的命令出現了錯誤,直接stop slave停止從機,然後reset master即可——>回到執行拜大哥命令前
边栏推荐
- 协程、asyncio、异步编程
- Ambari (VII) --- ambari integrated hue4.2 document (valid for personal test)
- NDK cross compilation
- Implementation of commit message standardized control in large projects
- Code submission specification
- flutter 实现摇一摇功能
- Installing redis on Linux
- QT -- communication protocol
- Modifying MySQL user name root under Linux
- Helloword routine for ROS
猜你喜欢

Software design of power control board

Leetcode learning records

golang gin框架进行分块传输

Disposition Flex

Section 8: DMA of zynq

Unity UI shadow component
![[thanos source code analysis series]thanos query component source code analysis](/img/e4/2a87ef0d5cee0cc1c1e1b91b6fd4af.png)
[thanos source code analysis series]thanos query component source code analysis

The solution of "user account control to continue, please enter administrator user name and password" appears in win10 Professional Edition

ACM笔记

kubernetes删除pod的流程的源码简析
随机推荐
Recommended system series (Lecture 5): Optimization Practice of sorting model
pip 更新到最新的版本
Ambari (IX) --- use expect to realize no interaction in ambri server setup phase (valid for personal test)
Section 8: DMA of zynq
At 19:00 on Tuesday evening, the 8th live broadcast of battle code Pioneer - how to participate in openharmony's open source contribution in multiple directions
SOC timer and interrupt configuration
HJ整数与IP地址间的转换
Kubelet garbage collection (exiting containers and unused images) source code analysis
Kubernetes cluster command line tool kubectl
Design of DSP image data stream
Soft exam -- software designer -- afternoon question data flow diagram DFD
Static resource compression reduces bandwidth pressure and increases access speed
kubelet垃圾(退出的容器和未使用的镜像)回收源码分析
Code submission specification
Modifying MySQL user name root under Linux
Hj21 simple password
Is it reliable to open a new bond registration account? Is it safe?
ACM notes
Redis one master multi slave cluster setup
Conversion between HJ integer and IP address