en
Language
  • en
  • cs
  • hu
  • de
  • fr
  • es
  • br
  • ru
  • kr
  • jp
AI translation
  • it
  • pl
  • tr

Migrate from Postgres to MySQL

Introduction

This guide will show you how to migrate your database from PostgreSQL to MySQL. This is useful for Easy8 server administrators who need to switch their database backend. We tested both free and premium tools and included step-by-step instructions for each.

Target Audience

  • Administrator

Prerequisites

Before starting, ensure you have:

  • Access to both the PostgreSQL and MySQL databases
  • Basic knowledge of SQL and terminal usage
  • Installed PHP if using the free script
  • Administrative rights on the system

How to Migrate Using Free Tool (pg2mysql)

Step 1: Download the conversion script

Use one of the following options:

Original script:

wget http://www.lightbox.ca/pg2mysql/pg2mysql-1.9.tar.bz2
tar -xvf pg2mysql-1.9.tar.bz2

Modified script for PHP 7.4:

wget https://www.easyredmine.com/ER/media/knowledge-base/pg2mysql-1.9.zip
unzip pg2mysql-1.9.zip

Step 2: Install PHP

sudo apt install php7.4-cli

Step 3: Create PostgreSQL dump

sudo -u postgres pg_dump --format p --inserts DBNAME_HERE > /path/to/file.sql

Step 4: Switch to script folder

cd pg2mysql-1.9/

Step 5: Run the conversion

php pg2mysql_cli.php /path/to/pd/dump/file.sql /path/where/to/save/mysql/file.sql

You should see:

Completed!     30820 lines        5539 sql chunks

Step 6: Modify dump file

Open the resulting .sql file and replace all engine definitions from MyISAM to InnoDB.

Step 7: Import into MySQL

mysql -u [user] -p [db_name] < /path/where/to/save/mysql/file.sql

Replace [user] and [db_name] with your actual database credentials.

Step 8: Add missing indexes

The script does not preserve indexes. You must manually add them or use your own script. Refer to a standard Easy8 schema for guidance.

How to Migrate Using Premium Tool (DBConvert)

Preparation

  1. Make both PostgreSQL and MySQL accessible remotely.
  2. Ensure login credentials are available.
  3. Install tool from: https://dbconvert.com/postgresql/mysql/

Migration Process

  1. Launch DBConvert wizard.
  2. Select PostgreSQL as the source, fill in connection details, and test the connection.
  3. Choose the database and tables to convert.
  4. Set destination (MySQL), enter details, and test the connection.
  5. Fix field type issues (e.g., change CHAR(1) to CHAR(2)).
  6. Start the conversion and wait for completion.
  7. Click "Exit". Conversion is done.

Price: $149 (one time)

Other Premium Options

pgs2scld

ESF Database Migration Toolkit

Conclusion

You have successfully learned how to migrate from PostgreSQL to MySQL using both free and premium tools. We recommend reviewing your output and checking indexes post-conversion to ensure full performance and functionality.

Related Topics and Further Reading

Try Easy8 in 30 days free trial

Access all features, SSL protected, no credit card required.