1

I have an old PHP application with a bunch of MySQL tables. I want to rewrite it with Rails(3) and want to import the old data. How can I write a migration-script to import the MySQL-Dump into a sqlite DB?

2 Answers 2

0

It's out of my merit to judge why migrate from mysql to sqlite3 db. Why not run your dev environment as well in mysql? anyway, following is the script.

#!/bin/sh 

mysqldump --compact --compatible=ansi --default-character-set=binary mydbname | 
grep -v ' KEY "' | 
grep -v ' UNIQUE KEY "' | 
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; 
} ' | sqlite3 output.db
1
  • Hm, that doesn't work quite well. (syntax error with "auto_increment", "unsigned", ...) Is there a better way?
    – f00860
    Aug 31, 2010 at 21:27
0

I solved the Problem with a DATA DB Dump (not the schema) and create the tables with another migration file and create_table.

1
  • How you solved, can you explain briefly, I need to old PHP application with a bunch of MySQL tables into Postgres DB in rails 5 May 29, 2017 at 7:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.