script to convert mysql dump sql file into format that can be imported into sqlite3 db

后端 未结 9 2215
说谎
说谎 2020-11-29 03:07

I have an export SQL file containing tables and data from MySQL and I want to import it into a Sqlite 3 DB.

What is the best way to do that?

Just importing t

9条回答
  •  醉酒成梦
    2020-11-29 03:31

    When the sqlite3 database is going to be used with ruby you may want to change:

    tinyint([0-9]*) 
    

    to:

    sed 's/ tinyint(1*) / boolean/g ' |
    sed 's/ tinyint([0|2-9]*) / integer /g' |
    

    alas, this only half works because even though you are inserting 1's and 0's into a field marked boolean, sqlite3 stores them as 1's and 0's so you have to go through and do something like:

    Table.find(:all, :conditions => {:column => 1 }).each { |t| t.column = true }.each(&:save)
    Table.find(:all, :conditions => {:column => 0 }).each { |t| t.column = false}.each(&:save)
    

    but it was helpful to have the sql file to look at to find all the booleans.

提交回复
热议问题