So, I got MySQL to work for my Ruby on Rails development environment. Let’s be clear about what I actually wanted:
- Ruby 1.9.1
- Rails 2.3.2
- Any version of MySQL whatsoever
- Any way whatsoever to make my up-to-date Ruby on Rails talk to that MySQL
I don’t care what version of MySQL. I don’t care if I have to force platforms for Gems or recompile or whatever. I never did care, and I’ll happily even dig through code to make manual changes before compiling or what-have-you. What I do care about is actually getting this to work, so I can finally stop tinkering and start doing something productive.
Well, I learned a lot on my way there. I had a glimpse at how extconf.rb works (because I had to figure out correct parameters), I dug through rails sources to find errors that you don’t even want to know about, had another good look at makefiles, and generally tried to understand what exactly didn’t work.
Also, there is a more efficient way to do this, as pointed out by Luis in the comments. Thanks!
So, in the end, it now works
This tutorial blog post on Code Elite was very, very helpful. So were Luis comments here and elsewhere (although me being quite the newbie when it comes to gcc and the likes, they went a bit over my head).
The Code Elite post is not the best at being copy-paste-able though, the formatting kinda ruins that. It does point out the correct steps to getting MySQL to work in Ruby (and consequently, Rails).
Long story short, these are the steps that lead to a working MySQL integration:
- Download Ruby 1.9.1 MinGW32 and the corresponding developer kit from the RubyInstaller download page. I prefer the zipped version to the one with installer, to be honest, but that’s just me.
- Get the 32-bit version (not 64-bit, or linking won’t work) of MySQL 5.0 (not 5.1, or nothing will work) from the MySQL download page. Again, I prefer the zipped version.
- Get the current mysql-ruby source (2.8.1, currently) from its FTP.
- Put Ruby into F:\Ruby or your path of preference. Add Ruby’s \bin path to your path variable. Close and re-open the command window to update the path.
- Install Rails – this is easy.
gem install rails - Put MySQL into F:\mysql (or your path, again). No adding to the path yet here.
- Put the contents of the mysql-ruby package into your Ruby path (I didn’t try other paths) and point your command line there, then run this:
ruby extconf.rb --with-mysql-lib=f:/mysql/lib/opt --with-mysql-include=f:/mysql/include
- Run make, then make install. Here is where 64-bit MySQL fails.
- Add the following to your path variable (substituting your MySQL location): F:\mysql\lib\opt;F:\mysql\bin. Again, close and re-open the command window to update the path.
- Run this to let Ruby know MySQL:
ruby -e 'require "mysql"'
- Get into a command prompt as admin (you might have to right-click a command prompt and “run as admin” to get to this) to install and start the MySQL service. To do that, run these in the mysql\bin directory:
mysqld-nt --install net start mysql - Now that the MySQL server is actually running, you can connect to it to change your root password:
mysqladmin -u root password topsecretpassword
Steps 1-3 are just downloads. Steps 4 and 5 already installs Ruby on Rails completely. Steps 6-12 then are for installing mysql (which is necessary first for the DLLs to be available to the compiler later) and then compiling the mysql-ruby package (driver?) from scratch into Ruby.
Interestingly, step 7 builds the makefile through Ruby (mostly, with some automated C mixed in), while step 8 actually compiles the C source through make and step 10 plugs this into Ruby. Steps 11 and 12 merely configure the MySQL server.
This should be it. And this time, I hope I did no forbidden or ugly things
For they know not what they do and stuff.



July 3rd, 2009 @ 2:51
I have been thinking of experimenting with Ruby on Rails, since you introduced it to me. I noticed there are quite a few posts or information coming out about this language. I wonder if this can be substituted for the php in Wordpress or such other content management systems?
July 3rd, 2009 @ 8:26
Excellent post mate, yours is the first result in google when I searched for ror on windows 7. I’m in the exact same boat as you re win 7 and ruby noob, will post back when I have finished all the steps :>.
July 3rd, 2009 @ 9:41
@Frank: Thanks a lot for your comment
Refactoring an entire CMS or blogging platform to use a completely different language altogether is a very daunting task – particularly when the two languages have different design paradigms. php and Ruby on Rails couldn’t be much more different there – essentially, not only would every last bit of code have to be rewritten, but fundamental application design concepts would have to be re-evaluated. It’s improbable that somebody ever undertakes that task, particularly because maintaining support for plugins (that are written in php, too) would be hard as well.
It would of course be perfectly possible to write a CMS on RoR from scratch. As a matter of fact, a simple blog (out of thin air) can be created in about 15 minutes:
http://rubyonrails.org/screencasts
I’d like to see something like that with php, guess it’d be more like 15 hours
As far as I’m aware, there are no such elaborate platforms like WordPress out yet that are written in RoR – the plugin and themes support, widgets, the advanced admin interface, are quite a lot more than the bare blogging necessities. No clue if we’ll see something like that with RoR in the future though
The main obstacle for Ruby on Rails, currently, is that every web hoster out there supports php, but only very few host Rails applications. There are Rails hosters, and I’m currently evaluating some for a project we’re working on, but they’re far less common than LAMP (Linux/Apache/MySQL/php) ones.
July 5th, 2009 @ 12:06
Thanks Couchy for that comment of yours
I’d be interested in hearing if installing RoR worked for you.
Sorry for my spam filter being overly strict, I blame all the spam I’m getting
Good thing I manually double-check before actually deleting things marked as spam
July 7th, 2009 @ 4:31
Hey Guido.
As I promised, simplified steps for your tutorial:
http://blog.mmediasys.com/2009/07/06/getting-started-with-rails-and-mysql/
Also, a SQLite3 one:
http://blog.mmediasys.com/2009/07/06/getting-started-with-rails-and-sqlite3/
Cheers.
July 7th, 2009 @ 8:12
Very nice, thanks
Those fat binary gems sure do look handy, and with your better tutorial, the MySQL support is still bundled as a gem, too.