Skip to content

Instantly share code, notes, and snippets.

@igniteflow
Last active January 12, 2020 11:35
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save igniteflow/5670193 to your computer and use it in GitHub Desktop.
Save igniteflow/5670193 to your computer and use it in GitHub Desktop.
Migrating from MySQL to Postgres in Ubuntu

Migrating from MySQL to Postgres in Ubuntu

Dump your database:

mysqldump --compatible=postgresql --default-character-set=utf8 -r databasename.mysql -u root databasename

Convert the dump to Postgres syntax using https://github.com/lanyrd/mysql-postgresql-converter:

wget https://raw.github.com/lanyrd/mysql-postgresql-converter/master/db_converter.py
chmod +rx db_converter.py
python dbconverter.py databasename.mysql databasename.psql

Install postgres:

apt-cache search postgres # find the most recent
sudo apt-get install postgresql-x.x

Create the database and insert the data:

sudo -u postgres createdb databasename
psql databasename -U postgres -h 127.0.0.1 < databasename.psql
@afdev82
Copy link

afdev82 commented Feb 7, 2017

python dbconverter.py databasename.mysql databasename.psql

It should be db_converter.py

@r0d0dendr0n
Copy link

I was migrating redmine from mysql to postgres. Afterwards I also had to:

  • Change type "bytea" to "text".
  • Execute "alter table journals alter COLUMN private_notes drop not null;".

Idk, maybe some more alters will be needed. So far my redmine on postgresql seems to work just fine. Thanks for your script!

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