How can I import an \"xxxx.sql\" dump from MySQL to a PostgreSQL database?
It is not possible to import an Oracle (binary) dump to PostgreSQL.
If the MySQL dump is in plain SQL format, you will need to edit the file to make the syntax correct for PostgreSQL (e.g. remove the non-standard backtick quoting, remove the engine definition for the CREATE TABLE statements adjust the data types and a lot of other things)
I could copy tables from MySQL to Postgres using DBCopy Plugin for SQuirreL SQL Client. This was not from a dump, but between live databases.
Mac/Win
Download Navicat trial for 14 days (I don't understand $1300) - full enterprise package:
connect both databases mysql and postgres
menu - tools - data transfer
connect both dbs on this first screen. While still on this screen there is a general / options - under the options check on the right side check - continue on error * note you probably want to un-check index's and keys on the left.. you can reassign them easily in postgres.
at least get your data from MySQL into Postgres!
hope this helps!
For those Googlers who are in 2015+.
I've wasted all day on this and would like to sum things up.
I've tried all the solutions described at this article by Alexandru Cotioras (which is full of despair). Of all the solutions mentioned there only one worked for me.
— lanyrd/mysql-postgresql-converter @ github.com (Python)
But this alone won't do. When you'll be importing your new converted dump file:
# \i ~/Downloads/mysql-postgresql-converter-master/dump.psql
PostgreSQL
will tell you about messed types from MySQL
:
psql:/Users/jibiel/Downloads/mysql-postgresql-converter-master/dump.psql:381: ERROR: type "mediumint" does not exist
LINE 2: "group_id" mediumint(8) NOT NULL DEFAULT '0',
So you'll have to fix those types manually as per this table.
In short it is:
tinyint(2) -> smallint
mediumint(7) -> integer
# etc.
You can use regex
and any cool editor to get it done.
MacVim
+ Substitute
:
:%s!tinyint(\w\+)!smallint!g
:%s!mediumint(\w\+)!integer!g
You can use pgloader.
sudo apt-get install pgloader
Using:
pgloader mysql://user:pass@host/database postgresql://user:pass@host/database
The fastest (and most complete) way I found was to use Kettle. This will also generate the needed tables, convert the indexes and everything else. The mysqldump
compatibility argument does not work.
The steps:
Download Pentaho ETL from http://kettle.pentaho.org/ (community version)
Unzip and run Pentaho (spoon.sh/spoon.bat depending on unix/windows)
Create a new job
Create a database connection for the MySQL source (Tools -> Wizard -> Create database connection)
Create a database connection for the PostgreSQL source (as above)
Run the Copy Tables
wizard (Tools -> Wizard -> Copy Tables)
Run the job