Import MySQL to MongoDB in 5 Steps (Plus SQL Server, PostgreSQL, Oracle) 
Tags: mongodb, sql, mysql, database
Published: 2019-05-17 15:36:58

---
title: Import MySQL to MongoDB in 5 Steps (Plus SQL Server, PostgreSQL, Oracle) 
published: true
description: A tutorial on how to import a SQL database to MongoDB in five easy steps.
tags: [mongodb, sql, mysql, database]
canonical_url: https://studio3t.com/knowledge-base/articles/import-sql-database-to-mongodb/
cover_image: https://studio3t.com/wp-content/uploads/import-sql-to-mongodb.png
---

In this tutorial, we’ll show you the quickest way to import an entire SQL database to MongoDB using [Studio 3T] (https://studio3t.com/) and its new [SQL Migration] (https://studio3t.com/knowledge-base/articles/sql-to-mongodb-migration/) feature.


## What you need

1. Your SQL database connection details. We’ll use MySQL in this tutorial but SQL Server, PostgreSQL, and Oracle are also supported.

1. Access to SQL Migration. Studio 3T offers a free 30-day trial [here] (https://studio3t.com/download/).

To illustrate a simple SQL database import, we’ll use the publicly available [world] (https://dev.mysql.com/doc/world-setup/en/world-setup-installation.html) database which contains three tables:

* city
* country
* countrylanguage

We’ll import each SQL table to a MongoDB collection, which means we should have three new collections in our target database.

## 1 – Open SQL Migration

Click on **SQL Migration > SQL -> MongoDB Migration** in the toolbar.

![Open SQL Migration from the toolbar](https://studio3t.com/knowledge-base/wp-content/uploads/sql-migration-toolbar.png "Open SQL Migration from the toolbar")


## 2 – Choose the source SQL connection

Click on **Click here to connect to a server** to open SQL Connection Manager.

### Open a saved connection

If you’ve already saved a connection, choose your source SQL connection from the list (we’ll use **sql-database**).

![Open SQL Connection Manager](https://studio3t.com/knowledge-base/wp-content/uploads/open-sql-connection-manager.png "Open SQL Connection Manager")

### Create a new connection

To create a new SQL connection, click on **New Connection**, enter the connection details under the **Server** and **SSH** tabs, and click **Save**.

![Create a new SQL connection](https://studio3t.com/knowledge-base/wp-content/uploads/new-sql-connection.png "Create a new SQL connection") 

## 3 – Choose your target MongoDB connection

Like Step 2, click on **Click here to connect to a server** to choose an existing MongoDB connection or to [create a new one] (https://studio3t.com/knowledge-base/articles/connect-to-mongodb/#create-a-new-connection-e-g-connect-to-mongodb-localhost).

Here we’ll choose **mongodb** as our target connection. This is where the three collections will be created.

![Choose target MongoDB connection](https://studio3t.com/knowledge-base/wp-content/uploads/choose-target-mongodb-connection.png "Choose target MongoDB connection")

## 4 – Choose SQL source tables
Studio 3T calls them “import units”, but an import unit simply means the SQL source table.

Click on **Add import units**.

We’ll choose the three **world** tables – `city`, `country`, and `countrylanguage` – to create a collection for each. 

By default, Studio 3T will map each table to a collection with the same name.
 
Click **OK**. All three tables should appear in the Overview.

![All SQL source tables should then appear in the Overview tab](https://studio3t.com/knowledge-base/wp-content/uploads/sql-source-tables.png "All SQL source tables should then appear in the Overview tab")

## 5 – Run the SQL import

It’s time to run the SQL import. Click on **Run Migration**.

![Click on Run Migration in the toolbar](https://studio3t.com/knowledge-base/wp-content/uploads/run-migration.png "Click on Run Migration in the toolbar")

Track your import in the Operations window on the bottom-left hand side.

![Track operations and double-check the MongoDB collections](https://studio3t.com/knowledge-base/wp-content/uploads/operations-window-and-mongodb-collections.png "Track operations and double-check the MongoDB collections")

Double-check that the **world** database was imported in the Connection Tree (top-left).

And finally, double-click on a collection (like `country`, highlighted above) to check if the data looks correct (and it does!)

## Next steps
The **world** database is quite simple – requiring no one-to-one or one-to-many table relationships – so the default mappings are sufficient for this import.

Note, however, that SQL Migration lets you fully control these mappings. Learn how to [merge multiple SQL tables into one MongoDB collection] (https://dev.to/kathrynvargas/how-to-merge-multiple-sql-tables-into-one-mongodb-collection-50d8/) to find out how you can use SQL Migration to do more complex imports.

If you're working with both MongoDB and SQL, **Studio 3T** makes it possible to [query MongoDB with SQL] (https://studio3t.com/knowledge-base/articles/sql-query/) and easily migrate data between the two databases. [Try it out, free for 30 days] (https://studio3t.com/download/).