In this tutorial, we’ll show you the quickest way to import an entire SQL database to MongoDB using Studio 3T’s SQL to MongoDB Migration tool.
What you need
- Studio 3T: Make sure you have Studio 3T up and running.
- Get your SQL database connection details ready. We’ll use MySQL in this tutorial, but Studio 3T also supports SQL Server, PostgreSQL, IBM DB2, and Oracle.
To illustrate a simple SQL database import, we’ll use the publicly available world database, which is available for download if you want to follow along. The world database 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
In Studio 3T, in the global toolbar, select SQL → MongoDB Migration:
![Import a SQL database to MongoDB with Studio 3T's SQL Migration tools](https://studio3t.com/wp-content/uploads/2019/04/import-sql-mongodb-migration-50.png)
2 – Choose the source SQL connection
To connect to the SQL server with the database and tables you want to migrate, click on Click here to connect to a server, next to Source SQL connection.
In the SQL Connection Manager dialog, you can either: connect to a saved connection or create a new connection, which if you’re a first-time user of Studio 3T you’ll likely need to set up a connection.
Open a saved connection
Select the source SQL connection from the list and click OK.
![Connect to the SQL server from which you want to import data.](https://studio3t.com/wp-content/uploads/2019/04/source-sql-connection-mongodb-import.png)
Create a new connection
To create a new SQL connection, click the New Connection button. In the New SQL Connection dialog, enter the connection details under the Server and SSH Tunnel tabs, and click Save.
![Create a connection to the SQL database from which you want to import data.](https://studio3t.com/wp-content/uploads/2019/04/new-sql-connection-mongodb-import-50.png)
3 – Choose your target MongoDB connection
Next to Target MongoDB connection, click on Click here to connect to a server, and similar to Step 2, select an existing MongoDB connection or create a new one.
Here we’ll choose Local as our target connection and click Connect. This is where Studio 3T will create three collections that correspond to the three tables.
![Connect to the MongoDB target server where you want to import the SQL tables.](https://studio3t.com/wp-content/uploads/2019/04/target-mongodb-connection-import.jpg)
4 – Choose SQL source tables
To add the tables, click the Add from source table button.
In the Select tables to import dialog, select the tables. We’ll choose the three world tables – city
, country
, and countrylanguage
– to create a collection for each. By default, Studio 3T maps each table to a collection with the same name.
Click OK. All three tables are displayed in the Overview tab.
![All the SQL source tables are displayed in the Overview tab.](https://studio3t.com/wp-content/uploads/2019/04/sql-source-tables-import-mongodb-1024x238.png)
5 – Run the SQL import
It’s time to run the SQL import. Click the Run migration button.
![Click on Run Migration in the toolbar to start importing the tables from the SQL database to your MongoDB server.](https://studio3t.com/wp-content/uploads/2019/04/run-import-sql-mongodb-migration.png)
You’ll see a confirmation dialog where Studio 3T refers to “import units”. Import units simply mean the SQL source tables.
You can track the import in the Operations pane which you’ll find in the lower-left side of Studio 3T.
![Track the import or migration operation from SQL to MongoDB.](https://studio3t.com/wp-content/uploads/2019/04/track-import-sql-mongodb-migration-1024x640.jpg)
When the import is complete, you can see the world database in the connection tree (top-left). Finally, double-click a collection (for example country
) to check if the data looks correct.
Next steps
We’ve illustrated a simple example in this article that uses the default mappings in the SQL to MongoDB Migration tool. You can explore the full SQL to MongoDB Migration documentation which includes defining relationships and customizing the fields in the target MongoDB collection.
Mappings also allow you to merge multiple SQL tables into one MongoDB collection, for example if you want to simplify the data structure and improve query performance.
![](https://studio3t.com/wp-content/uploads/2024/12/Blog-CTA-2-1024x536.gif)
This article was originally published by Kathryn Vargas and has since been updated.