Converting MySQL Dump SQL to Sqlite3 DB
Importing a MySQL dump SQL file into a SQLite3 database requires conversion to ensure compatibility.
The provided shell script offers an automated way to convert the dump file:
<code class="shell">#!/bin/sh # Usage: <dumpname> 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</code>
The script performs the following transformations:
The above is the detailed content of How to Convert a MySQL Dump SQL File to a SQLite3 Database?. For more information, please follow other related articles on the PHP Chinese website!