Import MySQL dump to PostgreSQL database

后端 未结 17 788
北海茫月
北海茫月 2020-12-04 10:05

How can I import an \"xxxx.sql\" dump from MySQL to a PostgreSQL database?

相关标签:
17条回答
  • 2020-12-04 10:05

    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)

    0 讨论(0)
  • 2020-12-04 10:05

    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.

    0 讨论(0)
  • 2020-12-04 10:07

    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!

    0 讨论(0)
  • 2020-12-04 10:08

    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
    
    0 讨论(0)
  • 2020-12-04 10:09

    You can use pgloader.

    sudo apt-get install pgloader
    

    Using:

    pgloader mysql://user:pass@host/database postgresql://user:pass@host/database
    
    0 讨论(0)
  • 2020-12-04 10:10

    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:

    1. Download Pentaho ETL from http://kettle.pentaho.org/ (community version)

    2. Unzip and run Pentaho (spoon.sh/spoon.bat depending on unix/windows)

    3. Create a new job

    4. Create a database connection for the MySQL source (Tools -> Wizard -> Create database connection)

    5. Create a database connection for the PostgreSQL source (as above)

    6. Run the Copy Tables wizard (Tools -> Wizard -> Copy Tables)

    7. Run the job

    0 讨论(0)
提交回复
热议问题