The invention discloses the synchronization method and synchronization system of the MySQL master slave database, in which the synchronization method includes the following steps: S1, whether to monitor the new binlog file of the main database, and S2, package and compress the newly generated binlog file if there is a new binlog file, and send it to the server if there is no new one. The binlog file is produced, then returns to S1; S3, unpack the compressed binlog file received from the server, get the complete data, and save it to the flash memory area; S4, read the operation records from the flash back storage area from the database, and realize the accurate synchronization of the master and slave database. The synchronization system includes monitoring unit, file pack compression unit, file unpacking verification unit, flashback storage area and reading unit. The synchronization method and synchronization system of the MySQL master slave database can synchronize the binlog files and store them from the server to realize the synchronization between the master and slave database.
【技术实现步骤摘要】
MySQL主从数据库的同步方法及同步系统
本专利技术涉及数据库
,具体提供了一种MySQL主从数据库的同步方法及同步系统。
技术介绍
数据库的主从模式可以实现读写分离,主从数据库本身具有延迟复制机制,但是,若主从数据同步的过程中发生网络故障,主从节点的数据将无法同步,造成主从数据的不一致,同时,现有MySQL数据库的延迟复制机制还存在如下问题:1、数据同步复制所采用的线程数不能随时改变;2、数据同步过程中,不能进行网络带宽限制干预,同步动作的延迟时间固定,不能根据网络可用带宽进行动态调整;3、不支持数据按照指定时间进行闪回。因此,研制一种独立于MySQL本身的延迟复制机制的数据同步方法及同步系统,成为人们亟待解决的问题。
技术实现思路
鉴于此,本专利技术的目的在于提供一种MySQL主从数据库的同步方法及同步系统,以解决MySQL本身的延迟复制方法在网络出现故障后,主从节点数据不一致且无法快速精确地完成数据的同步的问题。本专利技术一方面提供了一种MySQL主从数据库的同步方法,其中,主数据库设置于主服务器上,从数据库设置于从服务器上,其特征在于,包括如下步骤:S1 ...
【技术保护点】
MySQL主从数据库的同步方法,其中,主数据库设置于主服务器上,从数据库设置于从服务器上,其特征在于,包括如下步骤:S1:监视主数据库是否有新的binlog文件产生;S2:如果有新的binlog文件产生,则对新生成的binlog文件打包压缩并向从服务器发送,如果没有新的binlog文件产生,则返回S1;S3:从服务器对接收的压缩binlog文件进行解包校验,得到完整数据,并保存至闪回存储区;S4:从数据库读取闪回存储区的操作记录,实现主从数据库的精确同步。
【技术特征摘要】
1.MySQL主从数据库的同步方法,其中,主数据库设置于主服务器上,从数据库设置于从服务器上,其特征在于,包括如下步骤:S1:监视主数据库是否有新的binlog文件产生;S2:如果有新的binlog文件产生,则对新生成的binlog文件打包压缩并向从服务器发送,如果没有新的binlog文件产生,则返回S1;S3:从服务器对接收的压缩binlog文件进行解包校验,得到完整数据,并保存至闪回存储区;S4:从数据库读取闪回存储区的操作记录,实现主从数据库的精确同步。2.按照权利要求1所述的MySQL主从数据库的同步方法,其特征在于:S2中对新生成的binlog文件打包压缩并向从服务器发送包括:检测网络可用带宽;按照与检测到的网络可用带宽对应的压缩文件个数对新生成的binlog文件进行打包压缩并向从服务器发送。3.按照权利要求1所述的MySQL主从数据库的同步方法,其特征在于:S2中对新生成的binlog文件打包压缩并向从服务器发送包括如下步骤:检测网络可用带宽;将新生成的binlog文件打包压缩,之后,按照与检测到的网络可用带宽对应的延迟时间将打包压缩后的文件延迟向从服务器发送。4.按照权利要求1所述的MySQL主从数据库的同步方法,其特征在于:S2中对新生成的binlog文件打包压缩并向从服务器发送之前,还包括如下步骤:检测网络可用带宽;按照与检测到的网络可用带宽对应的传送线程数设置压缩文件的传送线程数。5.按照权利要求1所述的MySQL主从数据库的同步方法,其特征在于:S2中对新生成的binlog文件打包压缩并向从服务器发送之前,还包括如下步骤:检测网络可用带宽;按照与检测到的网络可用带宽对应的传送带宽设置传送压缩文件使用的带宽。6.MySQL主从数据库的同步系统,其中,主数据库设置...
【专利技术属性】
技术研发人员:苑明,王智,杨依霖,
申请(专利权)人:沈阳明曦科技有限公司,
类型:发明
国别省市:辽宁,21
还没有人留言评论。发表了对其他浏览者有用的留言会获得科技券。