Skip to content

bhmj/mysql-postgresql-converter

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 

Repository files navigation

MySQL to PostgreSQL Converter

Lanyrd's MySQL to PostgreSQL conversion script. Use with care.

This script was designed for our specific database and column requirements - notably, it doubles the lengths of VARCHARs due to a unicode size problem we had, places indexes on all foreign keys, and presumes you're using Django for column typing purposes.

How to use

First, dump your MySQL database in PostgreSQL-compatible format

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

Then, convert it using the dbconverter.py script

python db_converter.py databasename.mysql databasename.psql

It'll print progress to the terminal.

Finally, load your new dump into a fresh PostgreSQL database using:

psql -f databasename.psql

How to adjust

There are some constants in the script which try to assist you on incompatibilities:

DATE_DEFAULT = "1900-01-01"

Default date that is used to replace MySQL's "0000-00-00" date, which is not allowed in Postgres.

More information

You can learn more about the move which this powered at http://lanyrd.com/blog/2012/lanyrds-big-move/ and some technical details of it at http://www.aeracode.org/2012/11/13/one-change-not-enough/.

UPDATES

2023-08-04 : now this script is Python 3 ready. Python 2 needs adjustments, see "ADD THIS FOR PYTHON 2" in code.

About

Lanyrd's MySQL to PostgreSQL conversion script

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%