当前位置:网站首页>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即可——>回到執行拜大哥命令前
边栏推荐
- Install haproxy
- 云原生:云计算技术再次升级 开启全面云开发时代
- HJ prime factor
- Investment transaction and settlement of the fund
- Tencent continued to lay off staff in the second half of the year, and all business groups reduced by at least 10%. What do you think of this? Followers
- es6箭头函数中return的用法
- ACM notes
- 安全培训是员工最大的福利!2022新员工入职安全培训全员篇
- Study notes 22/1/18
- Sentinel mechanism of redis cluster
猜你喜欢

Hash slot of rediscluster cluster cluster implementation principle

What is EC blower fan?

Unity-UI-shadow组件

云原生:云计算技术再次升级 开启全面云开发时代

Idea package together, using compact middle packages to solve &

2021 programming language ranking summary

Design and implementation of spark offline development framework

Source code analysis of kubernetes' process of deleting pod

Safety training is the greatest benefit for employees! 2022 induction safety training for new employees

SOC clock configuration
随机推荐
asp. Net to search products and realize paging function
分析 NFT 项目的 5 个指标
Airflow2.x distributed deployment DAG execution failure log cannot be obtained normally
本周二晚19:00战码先锋第8期直播丨如何多方位参与OpenHarmony开源贡献
Soft test -- software designer -- database design of afternoon questions
Investment transaction and settlement of the fund
HJ string sort
Spark 离线开发框架设计与实现
8 figures | analyze Eureka's first synchronization registry
"Three routines" of digital collection market
扩展Prometheus的解决方案thanos的简介和几个月使用心得
Hj21 simple password
推荐系统系列精讲(第五讲): 排序模型的调优实践
Uninstall and reinstall the latest version of MySQL database. The test is valid
MMR rearrangement (similarity is calculated by editing distance and repeatability)
Ice - resources
HJ21 简单密码
Ice, protobuf, thrift -- Notes
Cloud native: cloud computing technology is upgraded again to open an era of comprehensive cloud development
Kubernetes cluster command line tool kubectl