Skip to content

Instantly share code, notes, and snippets.

@sbeam
Created October 14, 2010 19:05
Show Gist options
  • Save sbeam/626817 to your computer and use it in GitHub Desktop.
Save sbeam/626817 to your computer and use it in GitHub Desktop.
mysqldump -u $DB_USER -p$DB_PASS --compact --compatible=ansi --default-character-set=binary $DB_NAME | \
grep -v ' KEY "' | \
grep -v ' UNIQUE KEY "' | \
grep -v ' PRIMARY KEY ' | \
grep -ve '^SET ' | \
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/ 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=$1;
s/\\'\''/'\'\''/g;
s/\\n/\n/g;
s/\),\(/\);\n$a\(/g;
}
' > $DB_NAME.sqlite3.sql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment