This article shows the steps to migrate your database from MySQL to SQLite.
Pre-requites
- You need to have administrative access to the target MySQL database.
- You have SQLite3 installed on the target machine.
Steps
-
Create a dump of your MySQL database.
$ mysqldump -u USER -p -h HOST > ~/dump.sql -
Clone the mysql2sqlite tool from Github.
$ git clone https://github.com/mysql2sqlite/mysql2sqlite.git -
Use the mysql2sqlite tool to import data from your dump file into a fresh SQLite database file.
$ ./mysql2sqlite ./dump.sql | sqlite3 mydb.sqlite3 -
Update the Gemfile in your Rails App.
# gem 'mysql2', '~> 0.5' gem 'sqlite3', '>= 2.1' -
Run bundle install.
-
Update the database configuration.
default: &default adapter: sqlite3 pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> timeout: 5000 development: <<: *default database: storage/mydb.sqlite3 -
Copy the SQLite file into the storage directory.
-
That's all. You can now test your app.