search
HomeDatabaseMysql Tutorial关系型数据库和非关系型数据库的选择,以及替代方法(mysql替代mo

关系型数据库和非关系型数据库的选择,以及替代方法(mysql替代mongodb) 我做的项目因为涉及到大量的历史数据增加而采用的非关系型数据(mongodb),但是在实际开过程中遇到了很多问题,有开发方面的,也有管理方面的,于是我思考了用关系型数据库mysql代替非

关系型数据库和非关系型数据库的选择,以及替代方法(mysql替代mongodb)

 

我做的项目因为涉及到大量的历史数据增加而采用的非关系型数据(mongodb),但是在实际开过程中遇到了很多问题,有开发方面的,也有管理方面的,于是我思考了用关系型数据库mysql代替非关系型数据库mongodb的思路。  www.2cto.com  

 

目前还没有实施,因为对项目的改动会很大,希望大家能看看我的思路,最好能提一些意见,谢谢各位了。

 

方案的核心在于将目前一个数据库分割为两个数据库,一个当前交易库,一个历史数据查询库。

  www.2cto.com  

---------------------------详细方案如下----------------------------------

 

建立两个mysql数据库,一个是当前业务库叫bussDB,一个是数据中心库叫datacenterDB。

 两个数据库如何运作: 

1、datacenterDB库和bussDB库表结构基本完全一致。bussDB库存放正在进行的交易,datacenterDB库存放当前正在进行的交易和所有历史交易。

2、业务后台管理系统和业务前台网站都直接连接bussDB库进行正常业务操作。

3、历史查询、分析统计系统连接datacenterDB库进行查询统计。

4、bussDB库按照适合oltp(交易型)的库进行数据库存储和建模的优化。

5、datacenterDB库按照适合olap(分析型、数据仓库)的库进行数据库存储和建模的优化,可以使用表分区和集群等技术。

6、每天晚上,自动定时通过ETL工具(数据库同步工具)将bussDB库中的信息自动同步到datacenterDB库中。

7、设置程序自动在交易完成后180天以后将交易信息清除,清除之后关于该交易的查询在datacenterDB库中查询。

 

为什么要分为两个数据库:

1、适合交易的数据库和适合分析的数据库建模有一定区别,bussDB是交易型,而datacenterDB是查询分析型。

2、bussDB库需要保证快速响应,不因为历史数据的不断增大而影响速度,因此需要定期清除数据和数据转存。

3、bussDB库是一个事务型的数据库,需要保证事务完整性,因此不适合做集群,应采取垂直扩展(高性能服务器)。

4、datacenterDB库是一个数据仓库的数据库,需要集群和水平扩展(廉价PC,做集群)。

 

为什么要用关系型数据库而不用非关系型数据库。

 

1、在以上方式设计的bussDB库的状态下,对于增删改查操作,关系型数据库和非关系型数据库的性能开销基本一致,因为所有表的数据量都非常小,小于百万级,因为在千万级数据量以下,关系型数据库只要设置了索引,都是非常快的。

2、在性能方面一致的情况下,非关系数据库的缺点在于无法支持动态连接查询应用,即sql中的join操作,或者说是join效率不如关系型数据库高,另外也不支持分组(group)和统计操作(count/sum/avg等),在业务系统中存在大量的join操作,比如,报表打印、银行缴费对账、员工、机构、角色、交易、科目、字典等复杂应用都涉及到大量关联,所以非关系型数据库在这些处理方面不如关系型数据库灵活和性能高,编写的代码可读性和健壮性也较低。

3、关系型数据库的管理工具比如sqlyong,比非关系型数据库的管理工具更丰富,也更完善。对于数据库的DBA维护而言,关系型数据库的批量更新、导入、导出、备份、优化等方式和资料都丰富,对于开发人员的入门门槛,关系型数据库也比较低。

4、关系型数据库的发展历史和稳定性要超过非关系型数据库。

5、既然在性能一致的情况下为什么不用关系型数据库呢。

6、datacenterDB库就必须是用关系型数据库了,因为datacenterDB大量的统计应用都是基于sql中的统计函数的,比如查询交易业务性别比例、学历分布等,都涉及到sql操作,比如,join,group by xxx,sum(),count(),avg()等,这些都是非关系型数据库不支持的。

 

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
MySQL BLOB : are there any limits?MySQL BLOB : are there any limits?May 08, 2025 am 12:22 AM

MySQLBLOBshavelimits:TINYBLOB(255bytes),BLOB(65,535bytes),MEDIUMBLOB(16,777,215bytes),andLONGBLOB(4,294,967,295bytes).TouseBLOBseffectively:1)ConsiderperformanceimpactsandstorelargeBLOBsexternally;2)Managebackupsandreplicationcarefully;3)Usepathsinst

MySQL : What are the best tools to automate users creation?MySQL : What are the best tools to automate users creation?May 08, 2025 am 12:22 AM

The best tools and technologies for automating the creation of users in MySQL include: 1. MySQLWorkbench, suitable for small to medium-sized environments, easy to use but high resource consumption; 2. Ansible, suitable for multi-server environments, simple but steep learning curve; 3. Custom Python scripts, flexible but need to ensure script security; 4. Puppet and Chef, suitable for large-scale environments, complex but scalable. Scale, learning curve and integration needs should be considered when choosing.

MySQL: Can I search inside a blob?MySQL: Can I search inside a blob?May 08, 2025 am 12:20 AM

Yes,youcansearchinsideaBLOBinMySQLusingspecifictechniques.1)ConverttheBLOBtoaUTF-8stringwithCONVERTfunctionandsearchusingLIKE.2)ForcompressedBLOBs,useUNCOMPRESSbeforeconversion.3)Considerperformanceimpactsanddataencoding.4)Forcomplexdata,externalproc

MySQL String Data Types: A Comprehensive GuideMySQL String Data Types: A Comprehensive GuideMay 08, 2025 am 12:14 AM

MySQLoffersvariousstringdatatypes:1)CHARforfixed-lengthstrings,idealforconsistentlengthdatalikecountrycodes;2)VARCHARforvariable-lengthstrings,suitableforfieldslikenames;3)TEXTtypesforlargertext,goodforblogpostsbutcanimpactperformance;4)BINARYandVARB

Mastering MySQL BLOBs: A Step-by-Step TutorialMastering MySQL BLOBs: A Step-by-Step TutorialMay 08, 2025 am 12:01 AM

TomasterMySQLBLOBs,followthesesteps:1)ChoosetheappropriateBLOBtype(TINYBLOB,BLOB,MEDIUMBLOB,LONGBLOB)basedondatasize.2)InsertdatausingLOAD_FILEforefficiency.3)Storefilereferencesinsteadoffilestoimproveperformance.4)UseDUMPFILEtoretrieveandsaveBLOBsco

BLOB Data Type in MySQL: A Detailed Overview for DevelopersBLOB Data Type in MySQL: A Detailed Overview for DevelopersMay 07, 2025 pm 05:41 PM

BlobdatatypesinmysqlareusedforvoringLargebinarydatalikeImagesoraudio.1) Useblobtypes (tinyblobtolongblob) Basedondatasizeneeds. 2) Storeblobsin Perplate Petooptimize Performance.3) ConsidersxterNal Storage Forel Blob Romana DatabasesizerIndimprovebackupupe

How to Add Users to MySQL from the Command LineHow to Add Users to MySQL from the Command LineMay 07, 2025 pm 05:01 PM

ToadduserstoMySQLfromthecommandline,loginasroot,thenuseCREATEUSER'username'@'host'IDENTIFIEDBY'password';tocreateanewuser.GrantpermissionswithGRANTALLPRIVILEGESONdatabase.*TO'username'@'host';anduseFLUSHPRIVILEGES;toapplychanges.Alwaysusestrongpasswo

What Are the Different String Data Types in MySQL? A Detailed OverviewWhat Are the Different String Data Types in MySQL? A Detailed OverviewMay 07, 2025 pm 03:33 PM

MySQLofferseightstringdatatypes:CHAR,VARCHAR,BINARY,VARBINARY,BLOB,TEXT,ENUM,andSET.1)CHARisfixed-length,idealforconsistentdatalikecountrycodes.2)VARCHARisvariable-length,efficientforvaryingdatalikenames.3)BINARYandVARBINARYstorebinarydata,similartoC

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.