We build Web & Mobile Applications.

< All Articles

Using SQLite3 and MySQL on Windows

UPDATE! Luis Lavena has just released version 1.2.5 of the SQLite gem with added Windows goodness!

Way back in 2007, Rails 2.0.2 changed the default database from MySQL to SQLite3, making it easier for newcomers to get up and running with Rails quickly without having to worry about setting up a database. Unfortunately for Windows users, trying to install the SQLite3 gem with gem install sqlite3-ruby will result in the following error:

Building native extensions. This could take a while...
ERROR: Error installing sqlite3-ruby:
ERROR: Failed to build gem native extension.

This happens because the gem makes use of some C code which needs to be compiled. Most Windows users won’t have the necessary compilers setup and therefore gem installation fails.

Rather than give yourself a migraine trying to get the gem to compile, the simple solution is to use a slightly older version of the gem (version 1.2.3 instead of the latest version 1.2.4), as this has a pre-compiled Windows binary available. To use this gem you need to specify the version on the command line like so:

gem install sqlite3-ruby -v1.2.3

MySQL gem is borked (or yet another Windows problem)

If you get this bizarre error message when you try to use MySQL in your Ruby or Rails code:

undefined method `each` for #<Mysql:0x4841af8>

…and you’re running MySQL 5.1 then you’ve hit a compatibility problem between the gem and the MySQL 5.1 client library. One solution that has been found to work is to use an older version of the client library DLL. Simply download the DLL, copy it into your Ruby installation’s bin folder, restart MySQL and normal service should resume.

Updated on 15 October 2015
First published by Chris Anderton on 18 April 2009
© TheWebFellas Limited 2016
"Using SQLite3 and MySQL on Windows" by Chris Anderton at TheWebFellas is licensed under a Creative Commons Attribution 4.0 International License.