Export a MySQL Database to SQLite Database

前端 未结 7 1413
太阳男子
太阳男子 2020-11-28 08:33

Please help me with exporting a MySQL database into a SQLite database.

7条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-28 09:07

    mysql2sqlite.sh mentioned in the top post doesn't cope well with PRIMARY KEY lines, it doesn't write the trailing ) to complete the CREATE statement.

    This is what I did. I ran the mysql dump as:

    mysqldump --skip-create-options --compatible=ansi --skip-extended-insert --compact --single-transaction -h -u -p  > localdb.txt
    

    I then used grep to remove PRIMARY KEY and KEY:

    cat localdb.txt | grep -v "PRIMARY KEY' | grep -v KEY > localdb.txt.1
    

    I then used an editor to fix the file. When the keys are removed you end up with a CREATE statement that looks like:

    CREATE ...
      ...,
    )
    

    That trailing , has to be removed. In vi this expression matches them, ,$\n)

    Then you need to change all \' to ''

    Then you can do the import:

    sqlite3 local.sqlite3 < localdb.txt.1
    

    And that's it. I haven't found a single program that worked for me. I hope this helps someone.

提交回复
热议问题