Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save barseghyanartur/56876ab3acbd3d5d6ab7dcc477c29238 to your computer and use it in GitHub Desktop.
Save barseghyanartur/56876ab3acbd3d5d6ab7dcc477c29238 to your computer and use it in GitHub Desktop.
Convert MySQL dump to PostgreSQL dump

Prepare database dump using mysqldump:

mysqldump -u [username] -p [databaseName] --compatible=postgresql --default-character-set=utf8 > database.sql

Clone mysql-postgresql-converter project:

git clone git@github.com:lanyrd/mysql-postgresql-converter.git
cd mysql-postgresql-converter

Assuming that your mysql/mariadb dump is named database.sql, place that file into the mysql-postgresql-converter directory.

Convert mysql dump to postgresql dump:

python db_converter.py database.mysql database.psql

Replace datetime field with timestamp field.

sed -i 's/datetime(6)/timestamp with time zone/' database.psql

Import dump into postgres:

psql -U dbname -f database.pgsql
@barseghyanartur
Copy link
Author

barseghyanartur commented Jan 26, 2022

@sajid-nltsf:

It used to work back then. Raise an issue in the lanyrd/mysql-postgresql-converter.

@feyton
Copy link

feyton commented Jul 19, 2023

This work but a point to note is that I faced the issue when working with python3. It only worked when using python2 which I verified multiple times in a docker container

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment