├── README.rdoc └── sqlite3-to-mysql /README.rdoc: -------------------------------------------------------------------------------- 1 | 2 | == sqlite3-to-mysql 3 | 4 | Simple sed script for attempting to convert Sqlite3 sql 5 | to MySql sql. 6 | 7 | == Usage: 8 | 9 | sqlite3-to-mysql filename.sql > filename.new.sql 10 | 11 | == Notes 12 | 13 | Please note that sed needs to be in your $PATH 14 | 15 | Not guaranteed to work, but can serve as a starting point. 16 | 17 | Note that varchar will be translated to varchar(255). 18 | 19 | Decided to make this after trying the yaml_db gem, 20 | which I found to be excruciatingly slow for any dataset of considerable size. 21 | -------------------------------------------------------------------------------- /sqlite3-to-mysql: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | if test -z "$VARCHAR" 4 | then 5 | VARCHAR="255" 6 | fi 7 | 8 | sed \ 9 | -e '/PRAGMA.*;/ d' \ 10 | -e '/BEGIN TRANSACTION.*/ d' \ 11 | -e '/COMMIT;/ d' \ 12 | -e '/.*sqlite_sequence.*;/d' \ 13 | -e "s/ varchar/ varchar($VARCHAR)/g" \ 14 | -e 's/"/`/g' \ 15 | -e 's/CREATE TABLE \(`\w\+`\)/DROP TABLE IF EXISTS \1;\nCREATE TABLE \1/' \ 16 | -e 's/\(CREATE TABLE.*\)\(PRIMARY KEY\) \(AUTOINCREMENT\)\(.*\)\();\)/\1AUTO_INCREMENT\4, PRIMARY KEY(id)\5/' \ 17 | -e "s/'t'/1/g" \ 18 | -e "s/'f'/0/g" \ 19 | $1 20 | --------------------------------------------------------------------------------