MySQL 导出到 MongoDB
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3180709/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
MySQL export to MongoDB
提问by Alan Williamson
I am looking to export an existing MySQL database table to seed a MongoDB database.
我希望导出现有的 MySQL 数据库表来为 MongoDB 数据库提供种子。
I would have thought this was a well trodden path, but it appears not to be, as I am coming up blank with a simple MySQLDUMP -> MongoDB JSON converter.
我原以为这是一条很好的路径,但它似乎不是,因为我用一个简单的 MySQLDUMP -> MongoDB JSON 转换器来空白。
It won't take much effort to code up such a conversion utility.
编写这样的转换实用程序不会花费太多精力。
回答by Iván Rodríguez Torres
There are a method that doesn't require you to use any other software than mysql and mongodb utilities. The disadvantage is that you have to go table by table, but in your case you only need to migrate one table, so it won't be painful.
有一种方法不需要您使用除 mysql 和 mongodb 实用程序之外的任何其他软件。缺点是要一张一张表走,但你的情况只需要迁移一张表,所以不会很痛苦。
I followed this tutorial. Relevant parts are:
我跟着这个教程。相关部分是:
Get a CSV with your data. You can generate one with the following query in mysql.
SELECT [fields] INTO outfile 'user.csv' FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' FROM [table]
- Finally, import the file using
mongoimport
. That's all
使用您的数据获取 CSV。您可以在 mysql 中使用以下查询生成一个。
SELECT [fields] INTO outfile 'user.csv' FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' FROM [table]
- 最后,使用
mongoimport
. 就这样
回答by Andrew K
If you're using Ruby, you can also try: Mongify
如果你使用 Ruby,你也可以试试:Mongify
It will read your mysql database, build a translation file and allow you to map the information.
它将读取您的 mysql 数据库,构建一个翻译文件并允许您映射信息。
It supports:
它支持:
- Updating internal IDs (to BSON ObjectID)
- Updating referencing IDs
- Type Casting values
- Embedding Tables into other documents
- Before filters (to change data manually)
- and much much more...
- 更新内部 ID(到 BSON ObjectID)
- 更新参考 ID
- 类型转换值
- 将表格嵌入其他文档
- 过滤器之前(手动更改数据)
- 还有更多……
Read more about it at: http://mongify.com/getting_started.html
阅读更多相关信息:http: //mongify.com/getting_started.html
回答by Amala
回答by cedric
回答by sathis
If you are using java you can try this
如果你使用的是 java 你可以试试这个
回答by FullStack
For a powerful conversion utility, check out Tungsten Replicator
如需强大的转换实用程序,请查看Tungsten Replicator
I'm still looking int this one called SQLToNoSQLImporter, which is written in Java.
我仍在寻找一个名为SQLToNoSQLImporter 的工具,它是用 Java 编写的。
回答by Jared Alessandroni
I've ut a little something up on GitHub - it's not even 80% there but it's growing for work and it might be something other of you could help me out on!
我在 GitHub 上有一些东西 - 它甚至不到 80%,但它正在增长,而且它可能是你们其他人可以帮助我的东西!