CN105447111A - mysql与MongoDB数据同步的方法及其系统 - Google Patents

mysql与MongoDB数据同步的方法及其系统 Download PDF

Info

Publication number
CN105447111A
CN105447111A CN201510779001.5A CN201510779001A CN105447111A CN 105447111 A CN105447111 A CN 105447111A CN 201510779001 A CN201510779001 A CN 201510779001A CN 105447111 A CN105447111 A CN 105447111A
Authority
CN
China
Prior art keywords
mongodb
mysql
server
database
developing engine
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
CN201510779001.5A
Other languages
English (en)
Other versions
CN105447111B (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.)
Xiamen University
Jinguan Copper Industry Branch of Tongling Nonferrous Metals Group Holding Co Ltd
Original Assignee
Xiamen University
Jinguan Copper Industry Branch of Tongling Nonferrous Metals Group Holding 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 Xiamen University, Jinguan Copper Industry Branch of Tongling Nonferrous Metals Group Holding Co Ltd filed Critical Xiamen University
Priority to CN201510779001.5A priority Critical patent/CN105447111B/zh
Publication of CN105447111A publication Critical patent/CN105447111A/zh
Application granted granted Critical
Publication of CN105447111B publication Critical patent/CN105447111B/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)
  • Computer And Data Communications (AREA)

Abstract

本发明公开一种mysql与MongoDB数据同步的方法,在开发机上调用OpenReplicator,读取A服务器上日志文件,失败则启动A服务器mysql并联网成功,成功则执行步骤5.2;5.2)、在开发机上定义计数器n;5.3)、开发机读取A服务器上的第n行binlog,将赋值给字符串S1;5.4)、S1为空则同步结束,不为空判断S1是否包含insert\update关键字,包含则执行步骤5.5,否则n=n+1,执行步骤5.3;MongoDB上执行S2语句,失败则同步结束;成功则n=n+1并执行步骤5.3。本发明还公开一种采用上述方法的系统。本发明可发挥mysql与MongoDB这两者的优势。

Description

mysql与MongoDB数据同步的方法及其系统
技术领域
本发明涉及一种mysql与MongoDB数据同步的方法,特别是涉及一种能实现上述方法的系统。
背景技术
mysql是现有的一个关系型数据库管理系统。MongoDB是目前IT行业常用的一种非关系型数据库(NoSql),其灵活的数据存储方式备受当前IT从业人员的青睐。
因此,有必要针对mysql研发一种将mysql里面的数据同步到MongoDB数据库的方法,以便进行整合、开发。
发明内容
有鉴于此,本发明的目的在于提供一种mysql与MongoDB数据同步的方法。
本发明还提供一种mysql与MongoDB数据同步的系统。
为了达成上述目的,本发明的解决方案是:
一种mysql与MongoDB数据同步的方法,通过以下步骤实现:
1)、在开发机上搭建开发环境;
2)、在A服务器上安装mysql数据库,并将数据库引擎设置为INNODB,启动数据库;
3)、在B服务器上安装MongoDB数据库;
4)、在开发机上,打开Eclipse,新建一个工程,配置好依赖jar包;
5)、在开发机上新建一个类,在类里面编写数据同步代码,步骤如下:
5.1)、在开发机上调用OpenReplicator,读取A服务器上mysql的binlog日志文件,如果读取失败,则启动A服务器mysql并联网成功,联网成功之后执行步骤5.2;如果读取binlog日志文件成功,则执行步骤5.2;
5.2)、在开发机上定义计数器n,n=1;
5.3)、开发机读取A服务器上的第n行binlog,将赋值给字符串S1;
5.4)、如果S1为空,则同步结束,如果不为空,进一步判断S1是否包含insert\update关键字,如果包含则执行步骤5.5,否则n=n+1,执行步骤5.3;
5.5)、开发机将S1转为MongoDB可执行的字符串S2;
5.6)、开发机调用MongoDBJDBC驱动,连接MongoDB,如果连接失败,则启动B服务器MongoDB数据库并联网成功,如果联网成功则执行步骤5.7;
5.7)、调用MongoDB驱动,在MongoDB上执行S2语句,如果失败,则同步结束;如果成功,则n=n+1,并执行步骤5.3。
一种mysql与MongoDB数据同步的系统,采用如如前所述的方法。
采用上述方案后,本发明的mysql与MongoDB数据同步的方法具有以下有益效果:本发明的目的是让开发人员能够将将mysql数据同步到MongoDB。软件开发时直接从MongoDB取数据,从而发挥mysql与MongoDB这两者的优势
本发明的mysql与MongoDB数据同步的系统也具有以上有益效果。
附图说明
图1为本发明的mysql与MongoDB数据同步的方法的流程框图。
具体实施方式
为了进一步解释本发明的技术方案,下面通过具体实施例来对本发明进行详细阐述。
实施例一
如图1所示,本发明的mysql与MongoDB数据同步的方法主要通过以下步骤实现:
1)、在开发机上搭建开发环境;
2)、在A服务器上安装mysql数据库,并将数据库引擎设置为INNODB,启动数据库;其中,INNODB或InnoDB是MySQL的数据库引擎之一,为MySQLAB发布binary的标准之一。
3)、在B服务器上安装MongoDB数据库;
4)、在开发机上,打开Eclipse,新建一个工程,配置好依赖jar包;其中,jar包就是已经写好的一些类,将这些类进行打包,就可以将这些jar包引入项目中,然后就可以直接使用这些jar包中的类和属性。
5)、在开发机上新建一个类,在类里面编写数据同步代码,详细步骤如下:
5.1)、在开发机上调用OpenReplicator,读取A服务器上mysql的binlog日志文件,如果读取失败,则启动A服务器mysql并联网成功,联网成功之后执行步骤5.2;如果读取binlog日志文件成功,则执行步骤5.2;其中,OpenReplicator是一个用Java编写的MySQLbinlog分析程序。
5.2)、在开发机上定义计数器n,n=1;
5.3)、开发机读取A服务器上的第n行binlog,将赋值给字符串S1;
5.4)、如果S1为空,则同步结束,如果不为空,进一步判断S1是否包含insert\update这两个关键字。如果包含则执行步骤5.5,否则n=n+1,执行步骤5.3;
5.5)、开发机将S1转为MongoDB可执行的字符串S2;
5.6)、开发机调用MongoDBJDBC驱动,连接MongoDB,如果连接失败,则启动B服务器MongoDB数据库并联网成功,如果联网成功则执行步骤5.7;
5.7)、调用MongoDB驱动,在MongoDB上执行S2语句,如果失败,则同步结束;如果成功,则n=n+1,并执行步骤5.3。
本发明的mysql与MongoDB数据同步的系统,能实现如前所述的方法。
实施例二
本发明经测试通过后,即可部署到生产环境,进入实际应用阶段。
1、Mysql数据库为企业已经在运行中的数据库。
2、MongoDB数据库为企业将来大数据分析用到的NoSQL数据库集。
3、同步程序服务器为本专利中提到的程序部署环境,该服务器与Mysql和MongoDB通过TCP/IP协议通信。操作系统为CentOS6.6。
部署实施过程:
3.1、在同步程序服务器安装JDK。
3.2、将本发明开发的程序拷贝到/usr/local/tongbu/目录下。
3.3、在系统定时器设定定时任务,每秒调用一次该程序。
3.4、启动定时任务,观察MongoDB数据库。数据已经同步过来。同步成功。
上述实施例和附图并非限定本发明的产品形态和式样,任何所属技术领域的普通技术人员对其所做的适当变化或修饰,皆应视为不脱离本发明的专利范畴。

Claims (2)

1.一种mysql与MongoDB数据同步的方法,其特征在于,通过以下步骤实现:
1)、在开发机上搭建开发环境;
2)、在A服务器上安装mysql数据库,并将数据库引擎设置为INNODB,启动数据库;
3)、在B服务器上安装MongoDB数据库;
4)、在开发机上,打开Eclipse,新建一个工程,配置好依赖jar包;
5)、在开发机上新建一个类,在类里面编写数据同步代码,步骤如下:
5.1)、在开发机上调用OpenReplicator,读取A服务器上mysql的binlog日志文件,如果读取失败,则启动A服务器mysql并联网成功,联网成功之后执行步骤5.2;如果读取binlog日志文件成功,则执行步骤5.2;
5.2)、在开发机上定义计数器n,n=1;
5.3)、开发机读取A服务器上的第n行binlog,将赋值给字符串S1;
5.4)、如果S1为空,则同步结束,如果不为空,进一步判断S1是否包含insert\update关键字,如果包含则执行步骤5.5,否则n=n+1,执行步骤5.3;
5.5)、开发机将S1转为MongoDB可执行的字符串S2;
5.6)、开发机调用MongoDBJDBC驱动,连接MongoDB,如果连接失败,则启动B服务器MongoDB数据库并联网成功,如果联网成功则执行步骤5.7;
5.7)、调用MongoDB驱动,在MongoDB上执行S2语句,如果失败,则同步结束;如果成功,则n=n+1,并执行步骤5.3。
2.一种mysql与MongoDB数据同步的系统,其特征在于:采用如如权利要求1所述的方法。
CN201510779001.5A 2015-11-13 2015-11-13 mysql与MongoDB数据同步的方法及其系统 Active CN105447111B (zh)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201510779001.5A CN105447111B (zh) 2015-11-13 2015-11-13 mysql与MongoDB数据同步的方法及其系统

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201510779001.5A CN105447111B (zh) 2015-11-13 2015-11-13 mysql与MongoDB数据同步的方法及其系统

Publications (2)

Publication Number Publication Date
CN105447111A true CN105447111A (zh) 2016-03-30
CN105447111B CN105447111B (zh) 2017-12-12

Family

ID=55557289

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201510779001.5A Active CN105447111B (zh) 2015-11-13 2015-11-13 mysql与MongoDB数据同步的方法及其系统

Country Status (1)

Country Link
CN (1) CN105447111B (zh)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110837535A (zh) * 2018-08-16 2020-02-25 中国移动通信集团江西有限公司 数据同步的方法、装置、设备和介质

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102262662A (zh) * 2011-07-22 2011-11-30 浪潮(北京)电子信息产业有限公司 实现异构平台下数据库数据迁移的系统、装置及方法
US20140188986A1 (en) * 2013-01-02 2014-07-03 Sourcefire, Inc. Method and Apparatus for Identifying Computing Resource Trajectory
CN104572856A (zh) * 2014-12-17 2015-04-29 武汉科技大学 一种服务起源数据的融合存储方法
CN104778225A (zh) * 2015-03-27 2015-07-15 浙江大学 一种非结构化数据多存储系统中同步数据的方法

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102262662A (zh) * 2011-07-22 2011-11-30 浪潮(北京)电子信息产业有限公司 实现异构平台下数据库数据迁移的系统、装置及方法
US20140188986A1 (en) * 2013-01-02 2014-07-03 Sourcefire, Inc. Method and Apparatus for Identifying Computing Resource Trajectory
CN104572856A (zh) * 2014-12-17 2015-04-29 武汉科技大学 一种服务起源数据的融合存储方法
CN104778225A (zh) * 2015-03-27 2015-07-15 浙江大学 一种非结构化数据多存储系统中同步数据的方法

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
王晓河: "基于Mysql和MongoDB的协同备份方案研究与实现", 《电子科学技术》 *

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110837535A (zh) * 2018-08-16 2020-02-25 中国移动通信集团江西有限公司 数据同步的方法、装置、设备和介质

Also Published As

Publication number Publication date
CN105447111B (zh) 2017-12-12

Similar Documents

Publication Publication Date Title
CN106775723B (zh) 基于Android平台的系统固件定制的方法和Android设备
CN106919612B (zh) 一种上线结构化查询语言脚本的处理方法及装置
AU2015218520B2 (en) Service extraction and application composition
CN108304175B (zh) 代码文件隔离打包方法及装置
CN105843822A (zh) 一种修改日志级别的方法和装置
CN107346284B (zh) 一种应用程序的检测方法及检测装置
US20150106663A1 (en) Hash labeling of logging messages
WO2018209958A1 (zh) 可升级文件的升级方法、机顶盒和存储介质
CN106446019B (zh) 一种软件功能处理方法和装置
CN103399814B (zh) 自动化测试的方法及装置
US10248409B1 (en) Limiting the effects of source code patches on corresponding native-code patches
CN104636172B (zh) 一种应用升级方法和装置
CN104965776B (zh) 移动终端在恢复模式下查看日志的方法和系统
CN108037941B (zh) 基于公共插件的应用程序更新方法、电子设备、存储介质
CN104572644A (zh) 数据库更新装置和数据库更新方法
CN112953983A (zh) Sftp传输方法及装置
CN110659256A (zh) 多机房同步方法、计算设备及计算机存储介质
CN104133699A (zh) 设备系统软件升级方法与系统
CN114610640A (zh) 一种面向物联网可信执行环境的模糊测试方法和系统
CN107807844B (zh) 交通测试场景的生成方法、装置及计算机可读存储介质
CN104484176B (zh) 一种安卓系统窗口对象获取方法和装置
CN105447111A (zh) mysql与MongoDB数据同步的方法及其系统
CN103685471B (zh) 一种以独占方式对软件客户端进行更新的方法及系统
CN108984757A (zh) 一种数据导入方法及设备
CN110659022B (zh) 一种基于Java自动调用Python脚本的方法

Legal Events

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