To complete the following steps, you need to have access to your current MySQL database and have created the target database on your Database Instance.
Migrating MySQL databases to a Database for PostgreSQL using pgLoader
- pgloader
- postgresql
- mysql
- migration
pgLoader is an open-source database migration tool developed to simplify the process of migrating an existing database from one database engine to PostgreSQL.
The tool supports migrations from several file types and database engines like MySQL, MS SQL and SQLite.
In this tutorial, you learn how to migrate an existing remote MySQL database to a Database for PostgreSQL using pgLoader and an intermediate Development Instance running Ubuntu Linux.
Before you start
To complete the actions presented below, you must have:
- A Scaleway account logged into the console
- Owner status or IAM permissions allowing you to perform actions in the intended Organization
- An SSH key
- A Database Instance
- An Instance running on Ubuntu Bionic Beaver (18.04) or later
sudo
privileges or access to the root user
Setting up pgLoader to migrate your databases
-
Connect to your Instance using SSH.
-
Update the
apt
package cache, and upgrade the software already installed on the Instance:apt update && apt upgrade -y -
Install pgLoader using the
apt
package manager:apt install pgloader -
To check if the installation of pgLoader was successful, run the following command:
pgloader --versionAn output like the following displays:
pgloader version "3.6.3~devel"compiled with SBCL 2.1.11.debian
pgLoader is installed now, and you can begin the migration of your Database Instance.
Migrating your database
Database migration with pgLoader is designed to be very intuitive, and requires only one line of commands to migrate a MySQL database to a PostgreSQL database:
pgloader mysql://mysqluser:password@<mysql-server>:<mysql-port>/<source-database> postgresql://<pgsql-role>:password@<pgsql_server>:<postgresql-port>/<target-database>
Run the command above to automatically migrate your current database to the Database Instance. Depending on the size of your database, the migration may take some time. Once it has been completed, a summary is displayed:
2019-11-19T16:19:51.342000Z LOG report summary resettable name read imported errors total time------------------------------- --------- --------- --------- --------------fetch meta data 51 51 0 0.165sCreate Schemas 0 0 0 0.016sCreate SQL Types 0 0 0 0.017sCreate tables 24 24 0 0.525sSet Table OIDs 12 12 0 0.021s------------------------------- --------- --------- --------- --------------commentmeta 0 0 0 0.037scomments 1 1 0 0.080slinks 0 0 0 0.033spostmeta 1 1 0 0.123stermmeta 0 0 0 0.119sterm_relationships 1 1 0 0.192soptions 119 119 0 0.117susermeta 18 18 0 0.235sposts 3 3 0 0.167sterms 1 1 0 0.254sterm_taxonomy 1 1 0 0.272susers 1 1 0 0.273s------------------------------- --------- --------- --------- --------------COPY Threads Completion 4 4 0 0.328sCreate Indexes 39 39 0 1.656sIndex Build Completion 39 39 0 0.466sReset Sequences 11 11 0 0.085sPrimary Keys 12 12 0 0.132sCreate Foreign Keys 0 0 0 0.000sCreate Triggers 0 0 0 0.006sInstall Comments 0 0 0 0.000s------------------------------- --------- --------- --------- --------------Total import time 146 146 0 2.351s
Your data is now migrated. Update the database connection information in your software to communicate with your newly managed PostgreSQL database.