CN108415951A - 一种数据库控制方法和系统 - Google Patents

一种数据库控制方法和系统 Download PDF

Info

Publication number
CN108415951A
CN108415951A CN201810107411.9A CN201810107411A CN108415951A CN 108415951 A CN108415951 A CN 108415951A CN 201810107411 A CN201810107411 A CN 201810107411A CN 108415951 A CN108415951 A CN 108415951A
Authority
CN
China
Prior art keywords
binlog
data
database
snapshot
daily records
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN201810107411.9A
Other languages
English (en)
Other versions
CN108415951B (zh
Inventor
刘杰
史伟
闵宇
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Guangdong Ruijiang Cloud Computing Co Ltd
Guangdong Eflycloud Computing Co Ltd
Original Assignee
Guangdong Ruijiang Cloud Computing Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Guangdong Ruijiang Cloud Computing Co Ltd filed Critical Guangdong Ruijiang Cloud Computing Co Ltd
Priority to CN201810107411.9A priority Critical patent/CN108415951B/zh
Publication of CN108415951A publication Critical patent/CN108415951A/zh
Application granted granted Critical
Publication of CN108415951B publication Critical patent/CN108415951B/zh
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/27Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor

Landscapes

  • Engineering & Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Computing Systems (AREA)
  • Data Mining & Analysis (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

本发明公开了一种数据库控制方法和系统。方法包括基于负载均衡的方式访问数据库集群;连接数据库集群的所有数据库获取对应binlog日志,生成与binlog日志匹配的数据库的快照。系统包括由MySQL数据库组成的数据库集群、负载均衡服务器和binlog服务器,其中,所述负载均衡服务器基于负载均衡的方式访问所述数据库集群;所述binlog服务器从所述数据库集群的所有数据库获取对应binlog日志,生成与binlog日志匹配的数据库的快照。本发明通过负载均衡实现数据库集群的访问,通过binlog日志和快照保证数据库集群的安全性。

Description

一种数据库控制方法和系统
技术领域
本发明涉及数据库技术领域,尤其涉及一种数据库控制方法和系统。
背景技术
MySQL是当前应用最为广泛的开源数据库,该数据库本身提供了binlog的事务日志,并提供了一种主从的方式来进行数据的热备,但是这种热备方式存在非常多的弊端
1.容易裂脑,当主数据库由于宕机,导致从数据库上线之后,没有一个良好的机制来进行数据的重新同步
2.缺乏自动切换的机制
3.默认提供的互为主从方案只能支持两台数据库服务器。
发明内容
为了解决上述问题,本发明提供一种数据库控制方法和系统。
本发明采用的技术方案一方面为一种数据库控制方法,适用于MySQL数据库集群,包括:基于负载均衡的方式访问数据库集群;连接数据库集群的所有数据库获取对应binlog日志,生成与binlog日志匹配的数据库的快照。
优选地,还包括:连接数据库集群的所有数据库并获取对应binlog日志,基于预设的存储规则修改binlog日志的serverID标识、文件信息和偏移信息,存储所述binlog日志。
优选地,还包括:在预设的周期内,生成与binlog日志匹配的数据库的快照。
本发明采用的技术方案一方面为一种数据库控制系统,适用于上述方法,包括:由MySQL数据库组成的数据库集群、负载均衡服务器和binlog服务器,其中,所述负载均衡服务器基于负载均衡的方式访问所述数据库集群;所述binlog服务器从所述数据库集群的所有数据库获取对应binlog日志,生成与binlog日志匹配的数据库的快照。
优选地,所述MySQL数据库用于当出现异常时,从所述binlog服务器获取快照,并根据快照匹配的binlog日志从所述binlog服务器同步数据,同步完成后重新上线。
优选地,所述负载均衡服务器用于连接数据库集群的所有数据库并基于负载均衡单一访问对应MySQL数据库。
优选地,所述MySQL数据库用于当出现异常时,清除本地数据库的数据,从所述binlog服务器获取并将快照恢复到本地数据库,根据快照匹配的binlog日志从所述binlog服务器同步数据,同步完成后重新上线。
优选地,所述负载均衡服务器还用于基于预设的存储规则修改binlog日志的serverID标识、文件信息和偏移信息,将所述binlog日志传输至所述binlog服务器以进行存储。
本发明的有益效果为通过负载均衡实现数据库集群的访问,通过binlog日志和快照保证数据库集群的安全性。
附图说明
图1所示为基于本发明实施例的数据库集群系统的示意图。
具体实施方式
以下结合实施例对本发明进行说明。
基于发明的实施例,一种数据库控制方法,适用于MySQL数据库集群,包括:基于负载均衡的方式访问数据库集群;连接数据库集群的所有数据库获取对应binlog日志,生成与binlog日志匹配的数据库的快照。
方法还包括:连接数据库集群的所有数据库并获取对应binlog日志,基于预设的存储规则修改binlog日志的serverID标识、文件信息和偏移信息,存储所述binlog日志。
方法还包括:在预设的周期内,生成与binlog日志匹配的数据库的快照。
基于发明的实施例,一种数据库控制系统,适用于上述方法,包括:由MySQL数据库组成的数据库集群、负载均衡服务器和binlog服务器,其中,所述负载均衡服务器基于负载均衡的方式访问所述数据库集群;所述binlog服务器从所述数据库集群的所有数据库获取对应binlog日志,生成与binlog日志匹配的数据库的快照。
所述MySQL数据库用于当出现异常时,从所述binlog服务器获取快照,并根据快照匹配的binlog日志从所述binlog服务器同步数据,同步完成后重新上线。
所述负载均衡服务器用于连接数据库集群的所有数据库并基于负载均衡单一访问对应MySQL数据库。
所述MySQL数据库用于当出现异常时,清除本地数据库的数据,从所述binlog服务器获取并将快照恢复到本地数据库,根据快照匹配的binlog日志从所述binlog服务器同步数据,同步完成后重新上线。
所述负载均衡服务器还用于基于预设的存储规则修改binlog日志的serverID标识、文件信息和偏移信息,将所述binlog日志传输至所述binlog服务器以进行存储。
实施例的进一步改进,如图1所示的数据库集群系统,包括binlog服务器、负载均衡服务器和MySQL数据库集群,其中,
所述负载均衡服务器连接全部的MySQL数据库;
binlog服务器连接全部的MySQL数据库;
binlog服务器从MySQL数据库读取binlog日志,获取到binlog(即binlog日志的简称)后,将binlog中的serverID标识(用于区分MySQL数据库)修改为一个固定值A,并将binlog的文件信息(用于表明文件类型)和偏移信息(用于描述存储地址)按照一定的存储规则进行修改以便于存储;
binlog服务器将修改后的binlog日志存储,其中,如果binlog服务器同时在两台以上的MySQL数据库上获取到了binlog,则发出一个警告信息,并对比多份binlog中的主键和唯一键信息是否有冲突,如果有冲突,则再发出一个警告信息,并忽略其中有冲突的binlog信息(用途是保证不出现重复的存储,实现逐一从MySQL数据库读取binlog日志的目的);
设立一个时长T(作为算法/流程的基本要求,避免陷入死循环),在时长T的周期内,binlog服务器从MySQL集群数据库中生成一个MySQL数据库的快照,并在快照中记录该快照所对应的binlog文件信息和偏移信息(进行快照和对应binlog日志的匹配);
当MySQL数据库出现宕机启动之后,自动从binlog服务器获取一个最新的MySQL数据库快照;
清除MySQL数据库的本地数据库的所有信息;
将快照恢复到本地数据库中,并根据快照中的binlog偏移信息从biblog服务器上同步新的数据;
同步完成之后,将自身数据库上线。
发明设立了一个公共的负载均衡服务(使用者通过该负载均衡服务器访问MySQL数据库),并通过负载均衡保证了在多台MYSQL数据库的情况下,在同一个时间段内只有唯一确定的一台MySQL数据库处于服务状态,并设立了一个binlog服务器通过负载均衡服务器和MYSQL数据库进行互为主从的连接,由此绕开了MySQL的互为主从只能在两台服务器/数据库之间进行的逻辑限制,实现了数据库的多热备份的功能;所有的binlog都存储在唯一的binlog服务器上,避免了服务的数据库宕机恢复之后,复杂的数据同步问题,只需要从binlog服务器同步就ok。
以上所述,只是本发明的较佳实施例而已,本发明并不局限于上述实施方式,只要其以相同的手段达到本发明的技术效果,都应属于本发明的保护范围。在本发明的保护范围内其技术方案和/或实施方式可以有各种不同的修改和变化。

Claims (8)

1.一种数据库控制方法,适用于MySQL数据库集群,其特征在于,包括:
基于负载均衡的方式访问数据库集群;
连接数据库集群的所有数据库获取对应binlog日志,生成与binlog日志匹配的数据库的快照。
2.根据权利要求1所述的一种数据库控制方法,其特征在于,还包括:
连接数据库集群的所有数据库并获取对应binlog日志,基于预设的存储规则修改binlog日志的serverID标识、文件信息和偏移信息,
存储所述binlog日志。
3.根据权利要求1或2所述的一种数据库控制方法,其特征在于,还包括:
在预设的周期内,生成与binlog日志匹配的数据库的快照。
4.一种数据库控制系统,适用于权利要求1所述的方法,其特征在于,包括:
由MySQL数据库组成的数据库集群、负载均衡服务器和binlog服务器,其中,
所述负载均衡服务器基于负载均衡的方式访问所述数据库集群;
所述binlog服务器从所述数据库集群的所有数据库获取对应binlog日志,生成与binlog日志匹配的数据库的快照。
5.根据权利要求4所述的一种数据库控制系统,其特征在于,所述MySQL数据库用于当出现异常时,从所述binlog服务器获取快照,并根据快照匹配的binlog日志从所述binlog服务器同步数据,同步完成后重新上线。
6.根据权利要求4所述的一种数据库控制系统,其特征在于,所述负载均衡服务器用于连接数据库集群的所有数据库并基于负载均衡单一访问对应MySQL数据库。
7.根据权利要求5所述的一种数据库控制系统,其特征在于,所述MySQL数据库用于当出现异常时,清除本地数据库的数据,从所述binlog服务器获取并将快照恢复到本地数据库,根据快照匹配的binlog日志从所述binlog服务器同步数据,同步完成后重新上线。
8.根据权利要求6所述的一种数据库控制系统,其特征在于,所述负载均衡服务器还用于基于预设的存储规则修改binlog日志的serverID标识、文件信息和偏移信息,
将所述binlog日志传输至所述binlog服务器以进行存储。
CN201810107411.9A 2018-02-02 2018-02-02 一种数据库控制方法和系统 Active CN108415951B (zh)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201810107411.9A CN108415951B (zh) 2018-02-02 2018-02-02 一种数据库控制方法和系统

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201810107411.9A CN108415951B (zh) 2018-02-02 2018-02-02 一种数据库控制方法和系统

Publications (2)

Publication Number Publication Date
CN108415951A true CN108415951A (zh) 2018-08-17
CN108415951B CN108415951B (zh) 2022-01-11

Family

ID=63126819

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201810107411.9A Active CN108415951B (zh) 2018-02-02 2018-02-02 一种数据库控制方法和系统

Country Status (1)

Country Link
CN (1) CN108415951B (zh)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108984660A (zh) * 2018-06-28 2018-12-11 中译语通科技股份有限公司 一种MySQL数据库主从同步数据去重方法
CN110287273A (zh) * 2019-07-03 2019-09-27 成都路行通信息技术有限公司 基于监听MySQL数据库binlog变化实现数据同步的方法和系统

Citations (11)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101252603A (zh) * 2008-04-11 2008-08-27 清华大学 基于存储区域网络san的集群分布式锁管理方法
US20090055348A1 (en) * 2002-03-20 2009-02-26 International Business Machines Corporation Dynamic cluster database architecture
US20100017460A1 (en) * 2008-07-15 2010-01-21 International Business Machines Corporation Assymetric Dynamic Server Clustering with Inter-Cluster Workload Balancing
CN102065137A (zh) * 2010-12-21 2011-05-18 山东浪潮齐鲁软件产业股份有限公司 一种网络数据库表数据应用程序同步的方法
CN102546741A (zh) * 2011-08-31 2012-07-04 苏州华谷电子科技有限公司 云计算系统
CN104023082A (zh) * 2014-06-23 2014-09-03 浪潮电子信息产业股份有限公司 一种集群负载均衡的实现方法
US20140369202A1 (en) * 2008-04-14 2014-12-18 Huawei Technologies Co., Ltd. Method, device, and system for message distribution
CN104834724A (zh) * 2015-05-12 2015-08-12 广东睿江科技有限公司 一种数据库同步方法和装置
CN106570007A (zh) * 2015-10-09 2017-04-19 阿里巴巴集团控股有限公司 用于分布式缓存系统数据同步的方法和设备
CN106815097A (zh) * 2017-01-18 2017-06-09 北京许继电气有限公司 数据库容灾系统和方法
US20170235716A1 (en) * 2016-02-12 2017-08-17 International Business Machines Corporation Context driven artifact service management

Patent Citations (11)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20090055348A1 (en) * 2002-03-20 2009-02-26 International Business Machines Corporation Dynamic cluster database architecture
CN101252603A (zh) * 2008-04-11 2008-08-27 清华大学 基于存储区域网络san的集群分布式锁管理方法
US20140369202A1 (en) * 2008-04-14 2014-12-18 Huawei Technologies Co., Ltd. Method, device, and system for message distribution
US20100017460A1 (en) * 2008-07-15 2010-01-21 International Business Machines Corporation Assymetric Dynamic Server Clustering with Inter-Cluster Workload Balancing
CN102065137A (zh) * 2010-12-21 2011-05-18 山东浪潮齐鲁软件产业股份有限公司 一种网络数据库表数据应用程序同步的方法
CN102546741A (zh) * 2011-08-31 2012-07-04 苏州华谷电子科技有限公司 云计算系统
CN104023082A (zh) * 2014-06-23 2014-09-03 浪潮电子信息产业股份有限公司 一种集群负载均衡的实现方法
CN104834724A (zh) * 2015-05-12 2015-08-12 广东睿江科技有限公司 一种数据库同步方法和装置
CN106570007A (zh) * 2015-10-09 2017-04-19 阿里巴巴集团控股有限公司 用于分布式缓存系统数据同步的方法和设备
US20170235716A1 (en) * 2016-02-12 2017-08-17 International Business Machines Corporation Context driven artifact service management
CN106815097A (zh) * 2017-01-18 2017-06-09 北京许继电气有限公司 数据库容灾系统和方法

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
ALCÁZAR 等: ""Load Balancing Algorithm for Middleware Database Cluster"", 《PROCEEDINGS OF THE NATIONAL ACADEMY OF SCIENCES OF THE UNITED STATES OF AMERICA》 *
张树本 等: ""一种中间件数据库集群的负载均衡算法"", 《计算机工程》 *

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108984660A (zh) * 2018-06-28 2018-12-11 中译语通科技股份有限公司 一种MySQL数据库主从同步数据去重方法
CN110287273A (zh) * 2019-07-03 2019-09-27 成都路行通信息技术有限公司 基于监听MySQL数据库binlog变化实现数据同步的方法和系统

Also Published As

Publication number Publication date
CN108415951B (zh) 2022-01-11

Similar Documents

Publication Publication Date Title
US20150278030A1 (en) Distributed Database Synchronization Method and System
US8682903B2 (en) System and method for synchronized content directories on cluster devices
CN111209346A (zh) 一种区块链数据归档方法、装置和计算机可读存储介质
US10747776B2 (en) Replication control using eventually consistent meta-data
CN107895253A (zh) 一种电力交易功能进行微服务改造的方法
CN109101364B (zh) 双中心双活数据处理系统和方法
WO2015192661A1 (zh) 一种分布式存储系统中的数据同步方法、装置及系统
CN103902410B (zh) 云存储系统的数据备份加速方法
CN104243527A (zh) 数据同步方法、数据同步装置及分布式系统
CN102843403A (zh) 基于分布式文件系统的文件处理方法、系统及客户端
CN104424283A (zh) 一种数据迁移的系统和数据迁移的方法
CN104021200B (zh) 一种数据库的数据同步方法和装置
CN103744906A (zh) 一种数据同步系统、方法及装置
CN104252500A (zh) 一种数据库管理平台的故障修复方法和装置
CN111966467B (zh) 基于kubernetes容器平台灾备的方法及装置
CN108415951A (zh) 一种数据库控制方法和系统
CN106657169A (zh) 一种Redis中主从节点数据同步方法
CN106709066B (zh) 数据同步方法及装置
CN108228755A (zh) 基于日志解析技术的MySQL数据库到Hadoop平台的数据同步复制方法
CN114048217A (zh) 增量数据的同步方法和装置、电子设备和存储介质
CN106951456B (zh) 一种内存数据库系统及数据处理系统
CN109324942A (zh) 微服务的双活处理方法、装置及系统、设备、存储介质
CN113157701A (zh) 一种oracle数据库的双活机制部署方法及装置
CN114780506B (zh) 一种工艺文件的处理方法及电子设备
CN112202601B (zh) 副本集模式运行的两物理节点mongo集群的应用方法

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant