1、创建MySQL2Sqlite脚本mysql2sqlite.sh:(代码地址:https://gist.github.com/esperlu/943776)
#!/bin/sh # Converts a mysqldump file into a Sqlite 3 compatible file. It also extracts the MySQL `KEY xxxxx` from the # CREATE block and create them in separate commands _after_ all the INSERTs. # Awk is choosen because it's fast and portable. You can use gawk, original awk or even the lightning fast mawk. # The mysqldump file is traversed only once. # Usage: $ ./mysql2sqlite mysqldump-opts db-name | sqlite3 database.sqlite # Example: $ ./mysql2sqlite --no-data -u root -pMySecretPassWord myDbase | sqlite3 database.sqlite # Thanks to and @artemyk and @gkuenning for their nice tweaks. mysqldump --compatible=ansi --skip-extended-insert --compact "$@" | awk ' BEGIN { FS=",$" print "PRAGMA synchronous = OFF;" print "PRAGMA journal_mode = MEMORY;" print "BEGIN TRANSACTION;" } # CREATE TRIGGER statements have funny commenting. Remember we are in trigger. /^/*.*CREATE.*TRIGGER/ { gsub( /^.*TRIGGER/, "CREATE TRIGGER" ) print inTrigger = 1 next } # The end of CREATE TRIGGER has a stray comment terminator /END */;;/ { gsub( /*//, "" ); print; inTrigger = 0; next } # The rest of triggers just get passed through inTrigger != 0 { print; next } # Skip other comments /^/*/ { next } # Print all `INSERT` lines. The single quotes are protected by another single quote. /INSERT/ { gsub( /\047/, "