Tuesday, February 22, 2011

Working with MySQL and Ruby

Whoa, what's up SQL and MySQL?

Here's something I've recently realized about learning Ruby: I can't just learn Ruby. Ruby is going to be the thrust of what I'm learning and I'll spend the bulk of my time with it, but if my ultimate goal is to make a career change and become a full time Ruby programmer, I'll have to learn other languages as well.

This idea isn't as daunting as it might have been a month and a half ago, before I even had the seed of a desire to learn Ruby.

So here's something I've noticed about working with a bit of SQL and MySQL tonight. Computer languages share a lot of the same ideas. Sure, Ruby is more elegant than something like C++ and more modern than the Basic I learned in 9th grade, but the idea is the same. So the teeny, tiny little snippet of MySQL I wrote tonight was easier to understand than it would be if I hadn't also been working with Ruby for a month and a half or so.

I actually had to cut my database work short tonight because I couldn't get the MySQL gem to install, but I WAS able to write a program that allowed me to write to a database and retrieve information from it. Pretty cool, considering that's what I've been hot balls to learn since I cracked open Beginning Ruby.


  1. The MySQL gem is full of problems compiling on the latest OS X. The easiest route is simply to do some googling for your specific method of installing MySQL (homebrew, ports) and some other keywords like "rails gem" should be able to get you a working command in a minute or two. You should see two things, one a reference to ARCHFLAGS for 64bit, and two a directory to get some configuration variables from that is specific to your method of MySQL installation.

  2. That said, I would just stick with sqlite3 until you absolutely need to use something else, it is ridiculously easy and well suited for first steps.

  3. Yeah, I think I'll give sqlite3 a shot. I got homebrew working, but haven't been able to get the mysql gem installed.

  4. sqlite3 is still going to save you time maintaining users and databases as it doesn't require users, and databases are created automatically.

    When the time comes for MySQL, checkout the answers here: http://stackoverflow.com/questions/4966795/how-to-install-mysql-gem-on-mac-os-x

    Looks like the easiest way may be the mysql2 gem, or failing that, it has the proper install instructions for homebrew.

  5. Thanks for the input. Trouble installing the mysql gem has really killed my productivity this week. Skip it!