简体   繁体   English

从MongoDB迁移到MySQL

[英]Migrating from MongoDB to MySQL

We are in the process of migrating our mongodb's to MySQL. 我们正在将我们的mongodb迁移到MySQL。 Most of our client apps and infrastructure makes use of the 24 character mongo id object. 我们的大多数客户端应用程序和基础结构都使用了24个字符的mongo id对象。 I am now looking for a way in which I can generate a similar unique string but in SQL. 我现在正在寻找一种方法,我可以在SQL中生成类似的唯一字符串。

I've read up on the subject and some posts suggest that it's impossible to get the same mongo id in sql. 我已经阅读了这个主题,一些帖子表明在sql中获取相同的mongo id是不可能的。

I know the MongoID consists of: [4 bytes seconds since epoch, 3 bytes machine hash, 2 bytes process ID, 3 bytes counter] 我知道MongoID包括:[epoch以来的4个字节,3个字节的机器散列,2个字节的进程ID,3个字节的计数器]

I was thinking of writing a MySql function called get_mongo_id() which will return the following: 我正在考虑编写一个名为get_mongo_id()的MySql函数,该函数将返回以下内容:

LEFT(SHA2(UUID(),256),24) LEFT(SHA2(UUID(),256),24)

But I'm afraid it might still result in duplicates cause I'm only using the 1st 24 characters from a 64 character HASH. 但我担心它可能仍会导致重复,因为我只使用64个字符HASH中的前24个字符。

Have anyone ran into a similar problem before? 以前有人遇到过类似的问题吗? Any advise would be appreciated. 任何建议将不胜感激。

What you can do is have a string as your primary key and migrate it over. 您可以做的是将一个字符串作为主键并将其迁移。 Everything should work the same because MySQL can handle this. 一切都应该是一样的,因为MySQL可以处理这个问题。 Are you afraid of storage issues? 你害怕存储问题吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM