---
title: Migrating a Rails App from MySQL to SQLite database
url: https://calvin.my/posts/migrating-a-rails-app-from-mysql-to-sqlite-database
published: 2024-12-01
updated: 2026-09-17
category: Operations
tags:
- Rails
- MySQL
- sqlite
summary: The post outlines migrating a Rails application database from MySQL to SQLite. It requires administrative access to the MySQL database and SQLite installed locally. The process involves exporting the MySQL data, converting and importing it into a new SQLite database with a dedicated migration tool, replacing the MySQL dependency in the Rails project, updating database settings, and placing the SQLite file in the application’s storage directory before testing.
---

# Migrating a Rails App from MySQL to SQLite database

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

1. Create a dump of your MySQL database.

   ```bash
   $ mysqldump -u USER -p -h HOST > ~/dump.sql
   ```

2. Clone the mysql2sqlite tool from Github.

   ```bash
   $ git clone https://github.com/mysql2sqlite/mysql2sqlite.git
   ```

3. Use the mysql2sqlite tool to import data from your dump file into a fresh SQLite database file.

   ```bash
   $ ./mysql2sqlite ./dump.sql | sqlite3 mydb.sqlite3
   ```

4. Update the Gemfile in your Rails App.

   ```ruby
   # gem 'mysql2', '~> 0.5'
   gem 'sqlite3', '>= 2.1'
   ```

5. Run bundle install.

6. Update the database configuration.

   ```yaml
   default: &default
     adapter: sqlite3
     pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
     timeout: 5000

   development:
     <<: *default
     database: storage/mydb.sqlite3
   ```

7. Copy the SQLite file into the storage directory.

8. That's all. You can now test your app.
