Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mkhuda/1ea745a19f4f4101ff46a9de450cdf65 to your computer and use it in GitHub Desktop.
Save mkhuda/1ea745a19f4f4101ff46a9de450cdf65 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment