---
title: "Rails with SQLite3"
author: "dn365"
date: "2008-05-15T10:26:43Z"
tags: []
slug: "rails-with-sqlite3"
draft: false
lastmod: "2008-05-15T10:26:43Z"
id: 193189
url: "https://dn365.iteye.com/blog/193189"
---

SQLite 是個輕量級的資料庫程式，因為我想在NB上寫Rails，但是又不想裝MySQL好重，第一個就想到SQLite。關於SQLite的中文介紹，可以參考 簡介SQLite 和 SQLite使用教學。基本上 sqlite 就是一隻 command-line 程式而已，再加上一個資料檔(即一個資料庫)。

要在Rails中使用，Windows 下首先去 SQLite 網站下載 執行檔 跟 DLL檔，即 sqlite3.exe 跟 sqlite3.dll，放到 C:/ruby/bin 下。FreeBSD的話，執行 /usr/ports/databases/sqlite3/make install。

接著安裝 sqlite for Ruby gem，執行 gem install sqlite3-ruby，Windows 下選擇 win32 ，FreeBSD下選 ruby 的版本。

最後設定 database.yml :

    development:
      adapter: sqlite3
      dbfile: db/dev.db

    test:
      adapter: sqlite3
      dbfile: db/test.db

    production:
      adapter: sqlite3
      dbfile: db/prod.db

然後執行你寫好的 Migrations 即可把資料庫建立出來。

如果你想要 SQLite 的 GUI 管理介面，試試 SQLite Database Browser，也是一個檔案而已，不需要安裝。