Export a MySQL Database to SQLite Database

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

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

7条回答
  •  有刺的猬
    2020-11-28 08:46

    Personally I like the simple usage of mysqldump, yet some adjustments are need (depending on your art with Unix and what you want to do).

    Ex. for just one table (prods) with PK:

    $ mysqldump mysql prods -u ME -pPASS  --compatible ansi --compact |grep -v "^\/\*" |sqlite3 testme2.db
    $ mysqldump mysql prods -u ME -pPASS  --compatible ansi --compact |grep -v "^\/\*" |sqlite3 testme2.db
        Error: near line 1: table "prods" already exists
        Error: near line 7: UNIQUE constraint failed: prods.id, prods.ts
    $ sqlite3 testme2.db '.schema'
        CREATE TABLE "prods" (
          "id" varchar(30) NOT NULL DEFAULT '',
          "ts" int(11) NOT NULL DEFAULT '0',
          "val" double DEFAULT NULL,
          PRIMARY KEY ("id","ts")
        );
    

    For more complex things, probably better to write a wrapper, or then, use the already mentioned fantastic awk Linux shell script on Gist .

提交回复
热议问题