How to import from sql dump to MongoDB?

I suggest you dump Mysql data to a CSV file,also you can try other file format,but make sure the file format is friendly so that you can import the data into MongoDB easily,both of MongoDB and Mysql support CSV file format very well.

You can try to use mysqldump or OUTFILE keyword to dump Mysql databases for backup,using mysqldump maybe takes a long time,so have a look at How can I optimize a mysqldump of a large database?.

Then use mongoimport tool to import data.

As far as I know,there are three ways to optimize this importing:

  • mongoimport --numInsertionWorkers N It will start several insertion workers, N can be the number of cores.

  • mongod --njournal Most of the continuous disk usage come from the journal,so disable journal might be a good way for optimizing.

  • split up your file and start parallel jobs.

Actually in my opinion, importing data and exporting data aren't difficulty,it seems that your dataset is large,so if you don't design you document structure,it still make your code slower,it is not recommended doing automatic migrations from relational database to MongoDB,the database performance might not be good.

So it's worth designing your data structure, you can check out Data models.

Hope this helps.