Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如何从 MongoDB 迁移到 MySQL · /mongodb-to-mysql #87

Closed
draveness opened this issue Oct 27, 2017 · 5 comments
Closed

如何从 MongoDB 迁移到 MySQL · /mongodb-to-mysql #87

draveness opened this issue Oct 27, 2017 · 5 comments

Comments

@draveness
Copy link
Owner

draveness commented Oct 27, 2017

https://draveness.me/mongodb-to-mysql

@draveness
Copy link
Owner Author

Q: 我觉得改 uuid 如果只为了审美有点得不偿失。之前改过一次,真是特别的蛋疼,所有关联都要重新建立,一不小心就非常容易错。

A: 保留的话还要搞个 uuid 生成器,pk 都得改成字符串,reference 什么的也得改类型,都很麻烦,除此之外,32字节的 id 其实也会影响速度的。
想要完全摆脱历史遗留问题,能一次做了就都做了吧,而且只要这个迁移过程不是手动的就不容易出错,自动化的脚本能避免人搞出的很多问题,只要停机时间可以接受,还是都改了比较好

@draveness
Copy link
Owner Author

Q:好想知道从MySQL迁移到MongoDB的原因,再迁回来是怎么解决当时的问题的。

A: 迁移到 MongoDB 的时候我还不在这边,也不大清楚具体什么情况,我了解的就是当时它们觉得无 schema 的数据结构更易于开发和字段的修改,但是其实这问题我觉得是不存在的,虽然字段易于修改了,但是每次修改数据结构都要洗数据。

我是觉得当时是为了解决不存在的问题,毕竟我们作为一个 CPU 密集型的服务其实是不太在乎数据库能不能分片,性能高不高的。
对了,当时还有一个问题,因为要做数据分析,MongoDB 可以直接跑 js 脚本,所以迁移到了 MongoDB,但是其实数据分析的需求并不多,目前项目里同时存在了mongo 和 mysql,mongo 用来做数据分析,mysql 存业务数据

@draveness
Copy link
Owner Author

Q: 配图精美
MongoDB 迁移 PostgreSQL 好搞些,有 Array 字段支持,少很多工作。
Ruby China 之前搞过,往后就再也不碰 MongoDB 这个坑

A: 是,不过这边用的是mysql5.7 支持json 和 array 其实也还可以

@draveness
Copy link
Owner Author

draveness commented Oct 27, 2017

Q: 首先感谢作者的精彩分享,看了评论,谈下个人的几个想法:

  1. 目前的mongodb个人感觉是在各大主流数据库中,在无人看管下表现的最好的了。
  2. 任何数据库都是需要有人维护的。
  3. mysql迁移过来的时候做了关系和文档的转换,这次有做类似模型转换吗?
  4. objectid,是一个可以直接用来比较文档先后顺序的值,带有时间戳,另外提一句,mongodb的objectid是完全有能力支持1秒内的1000并发带来的主键不重复的。不是很清楚作者的重复id如何得到?

A:

  1. 不知道怎么回答。
  2. 数据库有人维护,这不是肯定的么,为什么要换到 ActiveRecord + MySQL 是因为要把每一次对数据的变动都用 Migration 记录下来,而不是通过 Mongoid + MongoDB,每次数据变动都只是仅仅修改模型,数据的变化过程完全就丢失了。你只能通过 git 记录去寻找模型是如何变成这样的
  3. 没有,并不明白这个问题什么意思
  4. 之前开发者直接对整个嵌入文档进行了复制,包括 _id

@draveness draveness added gitment and removed gitment labels Oct 29, 2017
@howardpen9
Copy link

喜歡你的blog的介面、還有支援的功能!

@draveness draveness changed the title 如何从 MongoDB 迁移到 MySQL 如何从 MongoDB 迁移到 MySQL · /mongodb-to-mysql Feb 4, 2020
Repository owner locked and limited conversation to collaborators Mar 21, 2022
@draveness draveness converted this issue into discussion #506 Mar 21, 2022

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Projects
None yet
Development

No branches or pull requests

2 participants