This is a follow up instruction set from previous post, but this time, using MySQL
Update: Gems are not officially released, no need to add
Update: Please see RubyInstaller wiki for updated instructions, specially related to Rails 3.
These steps are the same for Ruby 1.9 or Ruby 1.8, please feel free to download the installer from here
For this guide I’m going to use Ruby 1.9.1-p129, since it the coolest new version that all the guys are playing with
Now, start a Command prompt with Ruby (under start menu, inside Ruby 1.9.1-p129).
Getting the right MySQL version
While building the MySQL/Ruby bindings, we found that mixing versions of the bindings with different versions of MySQL installations ended on undesired results (abnormal program termination, weird errors, etc.)
For this guide, and because we are going to use binary gems, we are going to stick to MySQL version 5.0.83.
Now is time to download MySQL. For this guide, I’m going to install the essentials version, which contains only MySQL and command line tools, no Query Builder or any other administrative tool.
Please go to this page and download Windows Essentials (x86). Once downloaded you will end with
mysql-essential-5.0.83-win32.msi file. Execute it and install with defaults.
If you’re an advanced and savvy MySQL user, you can skip the following steps. For the sake of this guide, I’m going to list the simple options you must follow when installing it.
Once you installed MySQL, the installer should have started the Configuration Wizard page.
Inside of it, please apply the following options:
|Configuration Type||Detailed configuration|
|Server type||Developer Machine|
|Database usage||Transactional Database only|
|InnoDB datafile||Your option or leave defaults|
|Number of connections||Decision Support|
|Networking options||Check Add firewall exceptions|
|Character set||Best support for Multilingualism (UTF8)|
|Windows Options||Add to PATH if you want mysql available on every prompt|
|Security Options||Uncheck if you want root password be blank|
Once done with all this, on the summary screen, please click Execute to complete the configuration of MySQL Server.
Under some system, starting of MySQL server will fail during this wizard, but don’t be afraid, most of the times, this can be safely ignored.
To check everything was properly installed, please go to the Start Menu, and inside MySQL Server 5.0, click on MySQL Command Line Client
If you changed the root password, or, like me, leaved it unchecked, you can simply press enter when asked for the password and see that the server is running!
If you decided to add MySQL to the PATH, you will require to restart your computer so the PATH change is available to the system.
If you decided not to add MySQL to the PATH, please go, with Explorer to the location where you installed MySQL Server and copy
In my case, I found this file in
C:\Program Files\MySQL\MySQL Server 5.0\bin
Now, it is time to install the bindings.
For this version of Ruby, there is no official binary gems for both Ruby 1.8 and 1.9. So we are going to install the specially built version from RubyInstaller gems repository.
At the Command Prompt with Ruby, please enter the following command:
gem install mysql
This is going to install the special version of MySQL bindings. This version works with Ruby 1.8 and 1.9, since bundles fat binaries. You should expect a similar output like this:
Successfully installed mysql-126.96.36.199-x86-mingw32 1 gem installed
Now is time to install Rails and build our application. At the same command prompt, please enter the following command:
gem install rails
This is going to take a bit, since Rails and it’s dependencies takes around 2MB or so, and need to be downloaded and installed.
Once done, expect see at the screen something like this:
Successfully installed activesupport-2.3.2 Successfully installed activerecord-2.3.2 Successfully installed actionpack-2.3.2 Successfully installed actionmailer-2.3.2 Successfully installed activeresource-2.3.2 Successfully installed rails-2.3.2 6 gems installed
Creating a Rails application
Let’s name our application
rails mysqlapp --database=mysql
--database option indicates to Rails that we want to use MySQL instead of the default database adapter (SQLite3).
Rails will output a lot of lines when creating your application structure, just an excerpt of what to see:
... create config/database.yml create config/routes.rb create config/locales/en.yml create config/initializers/backtrace_silencers.rb create config/initializers/inflections.rb create config/initializers/mime_types.rb create config/initializers/new_rails_defaults.rb create config/initializers/session_store.rb create config/environment.rb ...
Configuring our Database
Now Rails have configured for us the name of the database we want to use, and you can verify it in
Rails will try to connect to
mysqlapp_development, but that database do not exist in our fresh new MySQL server.
So, let’s create it:
cd mysqlapp rake db:create
Just that, simple
db:create is going to connect to our MySQL server, and create the database for us.
Keep in mind that if you changed root password or want to use other MySQL user to connect to the database, you need to edit
database.yml to reflect those changes.
Let’s verify that everything is in place, using the following command:
And you should see something like this as result:
About your application's environment Ruby version 1.9.1 (i386-mingw32) RubyGems version 1.3.4 Rack version 1.0 bundled Rails version 2.3.2 Active Record version 2.3.2 Action Pack version 2.3.2 Active Resource version 2.3.2 Action Mailer version 2.3.2 Active Support version 2.3.2 Application root C:/Users/Luis/mysqlapp Environment development Database adapter mysql Database schema version 0
Now is up to you to create your models, controllers and views!
Some notes and considerations
On other post I’m going to guide you with steps on building the bindings against MySQL 5.1.36, since you will need to install the Ruby Development Kit and the development headers for MySQL.
If you find something wrong with the Ruby Installer, please report it here, but issues with your code, Rails or other are not responsability of RubyInstaller.
The binary gems provided at
gems.rubyinstaller.org are based on our forks of mysql bindings, which can be cloned and explored here at GitHub.
Keep in mind that some gems would not work under Ruby 1.9, or you will need a compiler (DevKit) for it. See previous post with details how to get those from our download page.