0

I used yaml_db gem to create a dump file of my mySQL database to use with SQLite However this is a full database export and I want to export data for specific table.

command = rake db:data:dump

Another way used

command:-mysqldump -uroot db_name table_name > db/database.yml

Those commands work for me but that they don't generate proper SQLite format. I think the format generated is SQL

How can I convert MySQL dump to SqLite.

Pieter Goosen
  • 9,050
  • 5
  • 29
  • 53
  • How do you see for using bash? for example: script to convert mysql dump sql file into format that can be imported into sqlite3 db https://gist.github.com/esperlu/943776 – brabertaser19 Nov 05 '14 at 08:42

1 Answers1

0

Since yaml_db gem works at db level, it has some functions that allow dowload only one table.

I wrote a patch that add a method to download only one table. Just put this code at config/initializers/yaml_db_extras.rb:

module YamlDb
  class Dump < SerializationHelper::Dump
    def self.dump_table_to_file(filename, table)
      file = File.new("#{filename}.yml", 'w')
      dump_table_columns(file, table)
      dump_table_records(file, table)
    end
  end
end

and use like this: YamlDb::Dump.dump_table_to_file('db/dump_users','users'), then you can use the dump file to load only the selected table at other app that uses yaml_db gem. If you name the dowload file db/data.yml at your destination app, you can load with rake db:data:load.

Alejandro Babio
  • 5,009
  • 15
  • 26