Migrating Data Between Databases Using DbVisualizer
Published: 2023-08-10 07:00:00

**In this article, we tell you how to migrate data between databases (a source database and a target database) while making use of DbVisualizer’s import and export features.**

---

### Tools used in this tutorial
[DbVisualizer](https://www.dbvis.com/download/), top rated database management tool and SQL client

---
Data importing and exporting are important in database development and data analysis because they allow for the integration of data from various originations, making it possible to work with a larger and more diverse set of data. This can be crucial in many fields, such as business, where data from multiple sources is needed to make well-informed decisions.

**Data import** is the process of bringing in data from an external source into a software system. Data import can involve a variety of exercises, such as converting data into a compatible format, cleaning and transforming data, loading data into a database, etc.

**Data export** on the other hand, is the process of taking data that is currently stored within a software program or system and conveying it to an external destination.

## Setting Up
For the purpose of this article, we’re going to utilize MySQL and PostgreSQL database management systems. To set up both database connections, we will need to first install both DBMS systems and then connect them to DbVisualizer.

### Setting Up MySQL
To set up MySQL, navigate to the [MySQL download page](https://downloads.mysql.com/archives/community/) to download the recommended installer for your operating system. Use these instructions: [Windows instruction](https://www.youtube.com/watch?v=OM4aZJW_Ojs), [macOS instruction](https://www.youtube.com/watch?v=CBtBZgmP22M), [Linux instruction](https://www.youtube.com/watch?v=BDShK0w1zAg) to help you install MySQL on Windows, macOS, and Linux operating systems respectively.

### Setting Up Postgres
To install Postgres, navigate to the [Postgres download page](https://www.postgresql.org/download/) and download the recommended installer for your operating system. You can follow this [tutorial](https://www.youtube.com/watch?v=EZAa0LSxPPU) for installation on macOS, this [installation tutorial](https://www.youtube.com/watch?v=IYCNAjyoHs8&t=5s) to help you install Postgres on a Windows operating system, and this [tutorial](https://www.youtube.com/watch?v=-LwI4HMR_Eg&t=599s) for installation on a Linux operating system.

### Setting Up DbVisualizer
To install DbVisualizer, navigate to the [DbVisualizer download page](https://www.dbvis.com/download/) to download the recommended installer for your operating system.

Run the download installer to install DbVisualizer on your computer. Open DbVisualizer once it has been installed, and you will be prompted to create a database connection.

## Connecting to Postgres
**Step 1:** Run the command below in the terminal of your computer to confirm the successful installation of the Postgres on your computer.

```
$ psql -U postgres
```
When the prompt opens, set a password for PostgreSQL from the prompt given.

Now, let us create a database called CPIforecast which will hold records of the average price change over time of consumer goods and services. Run the command below in the terminal of your computer to create the database.

```
$ CREATE DATABASE cpiforecast;
```
To check if the database has been created successfully in the list of databases, run the command below.

```
$ \list
```
You can verify that the CPIforecast database has been created.
<br />
![A view of the newly created Postgres database.
](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uk4m9p1mksuyj0d5yaos.png)
<figure><figcaption>A view of the newly created Postgres database.
</figcaption></figure>
<br />
**Step 2:** Start the DbVisualizer software and click on the “Create a Connection” button.
<br />
![Creating a database connection in DbVisualizer.](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n3w8omyhbldhs7zjtwdn.png)
<figure><figcaption>Creating a database connection in DbVisualizer.
</figcaption></figure>
<br />
![Searching and selecting Postgres driver in DbVisualizer
](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0g64xzgtigb2n0o5dssc.png)
<figure><figcaption>Searching and selecting Postgres driver in DbVisualizer
</figcaption></figure>
<br />
**Step 3:** Fill in the database connection input fields with the appropriate credentials.

- **Name:** CPI Forecast
- **Database:** cpiforecast
- **Database Userid:** postgres
- **Database Password:** Your Postgres password

Click on “Connect” after filling the required fields to successfully connect to the database.
<br />
![Object view tab for the Postgres connection.
](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1wfyz33cx566jugur747.png)
<figure><figcaption>Object view tab for the Postgres connection.
</figcaption></figure>
<br />

## Connecting to MySQL
To create your MySQL database connection, open the MySQL window and follow the steps below.

**Step 1:** Click on the “Start MySQL Server” button and enter your operating user password to start the server.

**Step 2:** Open the terminal window of your computer and run the command below to open the MySQL prompt.

```
$ mysql -u root -p
```
When the prompt opens, enter the password used during the MySQL installation process.

**Step 3:** Now, let us create a database called ‘CPIforecast Annex’ by running the command below in the terminal and pressing ‘enter’.

```
$ CREATE DATABASE cpiforecastannex;
```
To confirm if the database has been created, run the command below.

```
$ SHOW DATABASES;
```
We can see that the “cpiforecastannex” database has been created.

![A view of the newly created MySQL database.
](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mtwvwn0oztq7zk8vo86s.png)
<figure><figcaption>A view of the newly created MySQL database.
</figcaption></figure>
<br />
**Step 4:** Let us now connect the “cpiforecastannex” created to DbVisualizer. Under the “Databases” tab in the DbVisualizer window, click on the “create new database connection button”. Search and select ‘MySQL 8’ from the list of drivers.

![Creating the new database connection.](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c0ii7whgsbgz1ryj8akl.png)
<figure><figcaption>Creating the new database connection.
</figcaption></figure>
<br />
**Step 5:** Fill in the database connection input fields with the appropriate credentials.

- **Name:** ‘CPI forecast Annex’
- **Database:** ‘cpiforecastannex’
- **Database Userid:** ‘root’
- **Database Password:** password for root user.

Click on “Connect” after filling the required fields to successfully connect to the database.
<br />
![Object view tab for MySQL connection.
](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/khujyphwdal9jf26pzyr.png)
<figure><figcaption>Object view tab for MySQL connection.
</figcaption></figure>
<br />
Now, you have more than one database connected to DbVisualizer.

## Importing Data Table Into Postgres Using DbVisualizer
Before you can migrate data from one database to another, you will typically have to import data into one database before migrating it to another. The process of migration typically involves extracting data from the source database, transforming it if necessary, and then loading it into the target database.

**Step 1:** Navigate to this CPI Forecast file and download the dataset.

**Step 2:** Next, Open the database connection CPI Forecast tab tree as shown below.

![Opening database connection tab tree.
](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tvd5ws7hf71525m148e4.png)
<figure><figcaption>Opening database connection tab tree.
</figcaption></figure>
<br />
Open the database tab tree.
<br />
![Opening CPI Forecast database tab tree.](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/biryz01k47q9qaq6ikkb.png)
<figure><figcaption>Opening CPI Forecast database tab tree.</figcaption></figure>
<br />
Inside the Databases tab tree, open the cpi forecast database tab tree.
<br />
![Opening the cpi forecast tab tree.](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/68lkkdapzgh94gphidkn.png)
<figure><figcaption>Opening the cpi forecast tab tree.</figcaption></figure>
<br />
Inside the cpi forecast database tab tree, open the schemas tab tree.
<br />
![Opening the schemas tab tree.](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/75gm9jgffvnb3uigt5jq.png)
<figure><figcaption>Opening the schemas tab tree.
</figcaption></figure>
<br />
Inside the schemas tab tree, open the public tab tree.
<br />
![Opening the public tab tree.](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n8jhexjmhdv77todhe71.png)
<figure><figcaption>Opening the public tab tree.</figcaption></figure>
<br />
**Step 3:** Right-click on the ‘Tables’ and select ‘Import Table Data’ from the menu. Navigate to the location of the downloaded CPI forecast data set on your local computer and click on “open.”
<br />
![Selecting and opening CPI Forecast data file.
](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oxr1c56hpvvtariluznd.png)
<figure><figcaption>Selecting and opening CPI Forecast data file.</figcaption></figure>
<br />
**Step 4:** Click on “Next” until you get to the final import window as shown below.
<br />
![Making necessary effects in the final import window.
](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l0wplsws89nypsjdhuqy.png)
<figure><figcaption>Making necessary effects in the final import window.
</figcaption></figure>
<br />
Change the table name to “CPIForecastData.” Since SQL does not allow spaces in table names, let us rename the column name to something with no spaces by omitting all spaces in the “Changes in Consumer Price Indexes for food, 2020 through 2023” column name.

**Step 5:** Click on the ‘Next’ button and the ‘import’ button to import the table data into the Postgres database.
<br />
![Importing CPI Forecast table data.
](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ie3iwy5b2tovd3an8m81.png)
<figure><figcaption>Importing CPI Forecast table data.
</figcaption></figure>
<br />
You should see success in the import log as shown below.

![Import success.
](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1jc2p0i7vd9ug891kxgu.png)
<figure><figcaption>Import success.</figcaption></figure>
<br />
Once it has been imported, right-click on the table tab and click on the “Refresh Objects Tree” option. Click on the Data tab to see the table data as shown below.
<br />
![Imported CPI Forecast data table.
](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0x9myletonb4zzoghu8o.png)
<figure><figcaption>Imported CPI Forecast data table.
</figcaption></figure>
<br />

## Importing the Data From PostgreSQL Into MySQL
Since both Postgres and MySQL databases are connected, let us navigate to the schema and table we want to export from in the Postgres database. In this case, our table is ‘cpiforecastdata.’

**Step 1:** Right-click on the table and select “Export Data” from the context menu.
<br />
![Exporting table data into MySQL from Postgres.
](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c0j3vhinca2nrgbrph0h.png)
<figure><figcaption>Exporting table data into MySQL from Postgres.</figcaption></figure>
<br />
**Step 2:** In the Export Wizard, select the ‘SQL’ as the output format, select ‘SQL commander’ as the output destination and check the ‘GENERATE CREATE’ option.
<br />
![Implementing required settings.](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u5qcgsyvmyierv9v0d88.png)
<figure><figcaption>Implementing required settings.</figcaption></figure>
<br />
**Step 3:** Click on the export button and close the export window. This will open up the SQL commander as shown below.
<br />
![Queries for creating tables in the target database.
](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zvg3hpyw8vkj6pwr9y2i.png)
<figure><figcaption>Queries for creating tables in the target database.</figcaption></figure>
<br />
**Step 4:** Since we want to export the data to another database, let us select the target database connection. In this case, our target database (MySQL) is named as “CPI Forecast Annex”
<br />
![Selecting connection where you want to export the table data.
](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u5ur8100o07rv3ocar97.png)
<figure><figcaption>Selecting connection where you want to export the table data.</figcaption></figure>
<br />
**Step 5:** From the DbVisualizer menu bar, click on ‘SQL Commander’ and select Execute to execute the SQL commands. You should see success in the DbVisualizer log.
<br />
![Export log showing table data export success.](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zdeubdodqaowy15c9us0.png)
<figure><figcaption>Export log showing table data export success.</figcaption></figure>
<br />
Once it has been exported, navigate to the MySQL database tree, locate the table tab tree, right click on the table tab and refresh to see the exported table as shown below.
<br />
![Exported table data in MySQL.](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l7r3xloz14u9hc94oep6.png)
<figure><figcaption>Exported table data in MySQL.</figcaption></figure>
<br />
We can see that the table data we imported into our Postgres database has been successfully exported into our MySQL database. Migrating data between databases is an important step in data analysis because it allows for the integration of data from multiple sources. This can be useful in a variety of ways, such as: data warehousing, data integration, data distribution, data replication. The ability to migrate data between databases is critical for organizations that need to make sense of large and complex data sets. It allows them to easily integrate and analyze data from different sources, which in turn can lead to better decision-making, improved efficiency, and increased competitiveness.

## Conclusion
In this blog, we have learnt how to migrate data from one database to another while making use of DbVisualizer. This is an important factor in data analysis for organizations that make sense of large and complex data. We hope you enjoyed working with DbVisualizer.

If you're looking for an all-in-one database management tool, look no further than DbVisualizer. With its easy-to-use interface and powerful features, you can easily connect to and manage multiple databases, including MySQL, PostgreSQL, Oracle, and more. Plus, with its free trial and free version options, there's no risk in giving it a try. Upgrade your database management game with [DbVisualizer](https://www.dbvis.com/eval/). Try it out today!

## About the author
Leslie Gyamfi is a mobile/web app developer with a passion for creating innovative solutions. He is dedicated to delivering high-quality products and technical articles. You can connect with him on LinkedIn