MySQL导出到MongoDB [英] MySQL export to MongoDB

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

问题描述

我正在寻找导出现有的MySQL数据库表以植入MongoDB数据库的种子.

I am looking to export an existing MySQL database table to seed a MongoDB database.

我本以为这是一条被人践踏的道路,但事实并非如此,因为我用一个简单的MySQLDUMP-> MongoDB JSON转换器来空白.

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.

编写这样的转换实用程序无需花费很多精力.

It won't take much effort to code up such a conversion utility.

推荐答案

有些方法不需要您使用mysql和mongodb实用程序以外的任何其他软件.缺点是您必须逐表移动,但是在您的情况下,您只需要迁移一个表,这样就不会很麻烦.

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.

我遵循了教程.相关部分是:

I followed this tutorial. Relevant parts are:

  1. 获取包含数据的CSV文件.您可以在mysql中通过以下查询生成一个.

  1. 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]

  • 最后,使用mongoimport导入文件. 就这样
  • Finally, import the file using mongoimport. That's all
  • 这篇关于MySQL导出到MongoDB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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