结合使用MySQL和MongoDB [英] Using combination of MySQL and MongoDB

查看:75
本文介绍了结合使用MySQL和MongoDB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用MySQL和MongoDB的组合有意义吗?我基本上想做的是将MySQl用作原始数据备份"类型的东西,其中所有数据都存储在此处,而不是从那里读取.

Does it make sense to use a combination of MySQL and MongoDB. What im trying to do basically is use MySQl as a "raw data backup" type thing where all the data is being stored there but not being read from there.

数据也同时存储在MongoDB中,并且仅从mongoDB中读取数据,因为我不必进行联接和填充.

The Data is also stored at the same time in MongoDB and the reads happen only from mongoDB because I dont have to do joins and stuff.

例如,假设正在构建NetFlix

For example assume in building NetFlix

在mysql中,我有一张用于注释和电影的表格.然后,当在MySQL中发表评论时,我只需将其添加到表中,而在MongoDB中,我更新电影文件以保存此新评论.

in mysql i have a table for Comments and Movies. Then when a comment is made In mySQL i just add it to the table, and in MongoDB i update the movies document to hold this new comment.

然后,当我想获取电影和评论时,我只是从mongoDb中抓取了文档.

And then when i want to get movies and comments i just grab the document from mongoDb.

我主要关心的是因为将新" mongodb与MySQL进行了比较.在Mongo中发生意外情况的情况下,我们有一个MySQL备份,可以快速将应用程序回退到mysql和memcached.

My main concern is because of how "new" mongodb is compared to MySQL. In the case where something unexpected happens in Mongo, we have a MySQL backup where we can quickly get the app fallback to mysql and memcached.

推荐答案

在纸上听起来似乎是个好主意,但您需要考虑很多因素.这将使您的应用程序比您想象的要复杂.我会给你一些例子.

On paper it may sound like a good idea, but there are a lot of things you will have to take into account. This will make your application way more complex than you may think. I'll give you some examples.

您将要处理两个不同的系统,每个系统都有自己的行为.这些不同的行为将使保持所有内容同步变得非常困难.

You'll be dealing with two different systems, each with its own behavior. These different behaviors will make it quite hard to keep everything synchronized.

  • 在MongoDB中写入失败但在MySQL中成功写入时会发生什么?
  • 或者相反,例如,当违反MySQL中的列约束时?
  • 如果MySQL中发生死锁怎么办?
  • 如果您的架构更改怎么办?一次迁移很痛苦,但是您必须进行两次迁移.

您必须在应用程序代码中处理其中一些情况.这将我带到了下一点.

You'd have to deal with some of these scenarios in your application code. Which brings me to the next point.

您的应用程序需要与两个外部系统交互,因此您需要编写两个数据访问层.

Your application needs to interact with two external systems, so you'll need to write two data access layers.

  • 这些层都必须进行测试.
  • 两者都必须维护.
  • 应用程序的其余部分需要与这两层通信.
  • 将两层都抽象掉会引入另一层,这将进一步增加复杂性.

如果MongoDB失败,应用程序将退回到MySQL和memcached.但是,此时 memcached将为空.因此,MongoDB失败后的每个请求都将命中数据库.如果您的网站流量很高,那么也可以轻松删除MySQL.

Should MongoDB fail, the application will fall back to MySQL and memcached. But at this point memcached will be empty. So each request right after MongoDB fails will hit the database. If you have a high-traffic site, this can easily take down MySQL as well.

确定您认为MongoDB可能发生意外事件"的所有可能方式.然后针对每个案例使用最简单的解决方案 .例如,如果您担心数据丢失,请使用复制.如果是数据损坏,请使用延迟复制.

Identify all possible ways in which you think 'something unexpected' can happen with MongoDB. Then use the most simple solution for each individual case. For example, if it's data loss you're worried about, use replication. If it's data corruption, use delayed replication.

这篇关于结合使用MySQL和MongoDB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆