Question

I have MySql and Postgres databases. I have been working on Mysql DB which is populated with my data. Now for me to use heroku, I need to port it to Postgres. These are the steps I followed:

I exported data from my Mysql DB by simple dump command:

mysqldump -u [uname] -p[pass] db_name > db_backup.sql

I logged into my Postgres

sudo su postgres

Now when I try to import the sql into Postgres, it does not have access to db_backup.sql. I changed the permissions for all users and made the dump file read/write to all but still I cannot import the sql.

My question is what is the correct way to duplicate (both schema and data) from Mysql to Postgres. Also why am I not able to access the dump file even after changing the permissions? And if I have a dump from Mysql what are the chances that it runs into the issues while running it on Postgres (I do not have any procedural stuff in my Mysql. Just creation of tables and dumping data into those tables.)?

Thanks!

P.S. I am on Mac-Mavericks if that matters

Was it helpful?

Solution

While the primary part of the question was answered by @wildplasser I thought I would put the entire answer for people looking at porting MySQL data to Postgres.

After trying out multiple solutions, the easiest and quite smooth solution was this: https://github.com/lanyrd/mysql-postgresql-converter

This worked quite smoothly. But just one problem- it does not port any of Mysql sequences to Postgres. This means if you have auto-increment primary ids, you will have to change your Postgres schema separately and create serial sequences after the porting is done. Apart from that, it was quite smooth.

To talk about the permission issue, logging in as Postgres user and trying to access dump created by original user failed, the right way to do it was stay logged in as original user and use postgres user only for DB operation by using -U postgresuser command.

E.g.: psql -U postgres databasename < data_base_dump

While for many this must be the obvious way of doing it, I must admit it was one of those eureka moments for me :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top