Skip to content

Instantly share code, notes, and snippets.

@vaites
Created December 13, 2014 10:12
Show Gist options
  • Save vaites/4294e83a9cedf8457a31 to your computer and use it in GitHub Desktop.
Save vaites/4294e83a9cedf8457a31 to your computer and use it in GitHub Desktop.
Convert a MySQL database to SQLite
#!/bin/bash
read -p "User: " MYSQL2SQLITE_USER
read -s -p "Pass: " MYSQL2SQLITE_PASS
sqlt -f DBI --dsn dbi:mysql:$1 --db-user $MYSQL2SQLITE_USER --db-pass $MYSQL2SQLITE_PASS -t SQLite > schema.sql
mysqldump -u$MYSQL2SQLITE_USER -p$MYSQL2SQLITE_PASS --compatible=ansi --skip-opt $1 | grep "INSERT" > data.sql
iconv -f ISO-8859-1 -t UTF-8 data.sql > data-iso.sql
perl -pe "s/\\\'/''/g" data-iso.sql > data.sql
cat schema.sql | sqlite3 "$1.db" && cat data.sql | sqlite3 "$1.db"
rm -f schema.sql data.sql data-iso.sql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment