Problem:
Importing an exported MySQL dump SQL file into a SQLite3 database directly using the sqlite3 tool isn't successful. How can this be resolved?
Solution:
The following shell script can convert the MySQL dump file into a format that can be imported into SQLite3:
#!/bin/sh if [ "x" == "x" ]; then echo "Usage: <dumpname>" exit fi cat | grep -v ' KEY "' | grep -v ' UNIQUE KEY "' | grep -v ' PRIMARY KEY ' | sed '/^SET/d' | sed 's/ unsigned / /g' | sed 's/ auto_increment/ primary key autoincrement/g' | sed 's/ smallint([0-9]*) / integer /g' | sed 's/ tinyint([0-9]*) / integer /g' | sed 's/ int([0-9]*) / integer /g' | sed 's/ character set [^ ]* / /g' | sed 's/ enum([^)]*) / varchar(255) /g' | sed 's/ on update [^,]*//g' | perl -e 'local $/;$_=<>;s/,\n\)/\n\)/gs;print "begin;\n";print;print "commit;\n"' | perl -pe ' if (/^(INSERT.+?)\(/) { $a=; s/\'\''/'\'\''/g; s/\n/\n/g; s/\),\(/\);\n$a\(/g; } ' > .sql cat .sql | sqlite3 .db > .err ERRORS=`cat .err | wc -l` if [ $ERRORS == 0 ]; then echo "Conversion completed without error. Output file: .db" rm .sql rm .err rm tmp else echo "There were errors during conversion. Please review .err and .sql for details." fi
Explanation:
The above is the detailed content of How to Convert MySQL Dump Files into SQLite-Importable Format?. For more information, please follow other related articles on the PHP Chinese website!