Rails MySQL on Mac OS X 10.5.6

I was setting up a Rails development environment on my new MacBook Pro. The base installation includes Rails but does not include MySQL. After going through the process to upgrade and install everything, I thought my notes would be useful for others.

1. Update Rails. My Mac came with rails 1.2.6; this updated it to 2.3.2.

sudo gem update --system
sudo gem update rails

2. I installed MySQL from the official download. In addition to the server, they provide a preferences pane, “MySQL.prefPane”, to control starting and stopping the server.

Make sure to check out Sequel Pro.

3. Installing the native MySQL extension for Ruby requires the Ruby headers which are not installed by default. You will need to install the Developer Tools from your installation disk. You can verify:

$ls /System/Library/Frameworks/Ruby.framework/
Headers Resources Ruby Versions

$ls /System/Library/Frameworks/Ruby.framework/Headers
config.h dlconfig.h intern.h regex.h st.h
defines.h dln.h missing.h ruby.h util.h
digest.h dtrace.h node.h rubyio.h version.h
dl.h env.h re.h rubysig.h

If you do not have the headers available, you will receive the following error
trying to build the native extension.

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

/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
can't find header files for ruby.

4. Install the MySQL native driver using the gem tool.

$ sudo gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
Building native extensions. This could take a while...
Successfully installed mysql-2.7
1 gem installed

5. You should be good to go, build a new rails project and setup your database.yml

adapter: mysql
encoding: utf8
database: test_app
pool: 5
username: root
socket: /tmp/mysql.sock


2 Responses to “Rails MySQL on Mac OS X 10.5.6”

  1. This worked GREAT. Thanks!

  2. Dan Falcone Says:

    Great instructions. I had to use this command to install the gem:

    sudo env ARCHFLAGS=”-arch x86_64″ gem install mysql — –with-mysql-config=/usr/local/mysql/bin/mysql_config

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: