How to Migrate MongoDB Database to MySQL?

How to Migrate from MongoDB to MySQL database

MongoDB is amongst the most preferred databases for developers today. It is easy to use and works magically on unstructured data. Several data objects are stored as separate documents in the collection, unlike the traditional relational databases. However, with all the pros, there are a few cons too.

MongoDB does not support well-defined relationships, and you may end up having a lot of duplicate data. Duplicate data could also result in data becoming corrupted. Hence, to avoid complications, people prefer to migrate from MongoDB to MYSQL.

Experts at DEV IT have curated this article to help you migrate from MongoDB to the MYSQL database.

While there are multiple ways to archive the MongoDB to MYSQL migration, one of the simplest ways is using Studio 3T.

You may download Studio 3T from here

Robomongo Studio 3T
MongoDB Credential
MySQL Credential

Follow the steps mentioned below to migrate from MongoDB to the MYSQL database:

  • Open Robomongo Studio 3T
  • Open Connection (File-> Connect). The connection dialogue box will open, as shown below.
  • Click on New Connection. The following pop-up shall show.
New connection
  • Fill in the Connection Name, Connection Type, Server, and Port, and then double-check your connection by clicking on the Test Connection button.
  • Save your Connection.
  • Click on the Connect button, and your MongoDB connection will be established.

You shall now see Robomongo Studio 3T Dashboard, as shown below. 

  • Create a new Database or New Collection.

You may see that I have already created a new collection in the existing database.

See the county collection (Table) and already inserted documents below.

Studio 3T collection table
  • Now this (country) collection will convert to MySQL with the help of Studio 3T.
  • Select SQL Migration
  • Select MongoDB – SQL Migration
Select MongoDB

You will see an ‘open Migration to SQL Tab’ option as shown below.

open Migration to SQL Tab
  • Select the SQL target connection/directory. You will see two options: Directory or Server. Select the Server option.
  • Then click on the “click here to connect to a server” link.
  • Open SQL Connection Manager
  • To create a new MySQL connection, click on New Connection.
  • Enter MySQL Host, Username, Password, Port, Database.
  • Click on the OK button, and a connection has been established.
SQL Connection manager

The MySQL server will be connected, and the following screen will show.

All collections that you wish to migrate into MYSQL will appear here.

  • Click all the checkboxes and then click on the Mapping tab.

All the mapping-related details will show here, along with the MySQL table.

MYSQL table

See that we have one document with a nested object.

The SQL will create three tables, namely countries, countries_translations, countries_translations_object.

  • Now click on the run migration button. And your migration process will create several MySQL tables.
  • When it’s run successfully, you may open the MySQL database and see your MongoDB countries collections migrated to the MySQL database.

Here is when your migration of MongoDB to MySQL database will complete. I hope you are now transparent with the migration process. In case of any queries, do not hesitate to get in touch with an expert.

The following two tabs change content below.
Arpita Mehta

Arpita Mehta

Sr. Software Developer (PHP) at Dev Information Technology Ltd.
My primary focus and inspiration is Web Development. I am constantly experimenting with new technologies and techniques.

One thought on “How to Migrate MongoDB Database to MySQL?

Leave a Reply

Your email address will not be published.