Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there any command line tool for converting the MySQL database to PostgreSQL? I'd also like to know if there is a way to convert the database using the normal mysqldump command.

share|improve this question
Start here:… – a_horse_with_no_name Mar 29 '12 at 6:37
Whenever I see this, I cry tears of joy. – rfusca Jul 27 '12 at 16:01 – a_horse_with_no_name Nov 7 '15 at 12:59

have you tried:

mysqldump --compatible=postgresql dbname > export.sql

then do this to escape quotes

sed "s/\\\'/\'\'/g" export.sql > export1.sql

may need some more massaging so look at mysqldump doco more closely.

share|improve this answer
I have tried the method given by you already but it is giving error when restoring in the postgresql – Mughil Mar 29 '12 at 11:58
@Mughil what is the error? – Janus Troelsen Jul 29 '12 at 0:04

Here are a few open source tools, that can be very helpful:

FromMySqlToPostgreSql is a feature-reach tool and very easy to use.
It maps data-types, migrates constraints, indexes, PKs and FKs exactly as they were in your MySQL db.
Under the hood it uses PostgreSQL COPY, so data transfer is very fast.
FromMySqlToPostgreSql written in PHP (>= 5.4).

pgloader   is a data loading tool for PostgreSQL, using the COPY command. Its main advantage over just using

, and over using a Foreign Data Wrapper, is its transaction behaviour, where pgloader will keep a separate file of rejected data, but continue trying to copy good data in your database. The default PostgreSQL behaviour is transactional, which means that any erroneous line in the input data (file or remote database) will stop the entire bulk load for the table. pgloader also implements data reformatting, a typical example of that being the transformation of MySQL datestamps 0000-00-00 and 0000-00-00 00:00:00 to PostgreSQL
value (because our calendar never had a year zero).
pgloader written in LISP and distributed as source code, so you you need to compile it before using.

Hope it will help you...

share|improve this answer

There is actually a free migration tool that's quite easy to use, developed by EnterpriseDB themselves. It can be installed via the StackBuilder: Migration Toolkit

share|improve this answer

You can use EnterpriseDB Migration Wizard, for example.

It can symply migrate OracleDB. But for Mysql, it has some limitations, for example, it not supports views, triggers, stored procedures.

For more, see EDB Migration Toolkit. Not sure, but it can be possible to migrate mysql->oracle->postgresql saving your stored procedures (in case they exists).

Grep this: Database and SQL Migration Tools

share|improve this answer

I recently use a non-free tool from DBConvert to convert an access database to postgres, and found it well worth the money compared to the amount of time I wasted trying to do it reliably for free. The sell a similar tool for MySQL<->postgres, which I have not used, but may well be worth considering unless you are only interested in command line tools.

In case you are wondering I am not affiliated with them in any way :-)

share|improve this answer

This is just to add to the existing answers, which helped me find this solution. I used FromMySqlToPostgreSql. All you need to do is to download and extract FromMySqlToPostgreSql, make a copy of the sample config file, set the db connection values in it, and run the index file with the following command:

php index.php config.xml

Simple yet effective!

share|improve this answer
Could you edit your post with a link to this tool, please? – dezso Nov 26 '15 at 10:45
Sorry, i forgot that. Added! – toing_toing Nov 26 '15 at 10:47
Ah, this is funny. Have you realized that the author of the tool has posted an answer, too? ;) Now I did. – dezso Nov 26 '15 at 10:51
I'm flattered! He hasn't described much about his own wonderful plugin though. – toing_toing Nov 26 '15 at 10:59

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.