UPDATED 12-05-2008: The instructions in this article were written for Tiger. With the release of Rails 2.21 this article’s been getting a lot more traffic and the instructions here needed to be updated. What you see here are instructions that should work for most installations of MySQL on the Mac.
When I got the Macbook Pro in March 2007, I immediately installed Ruby, Rails, Subversion, etc, using this tutorial from Hivelogic. http://hivelogic.com/narrative/articles/ruby-rails-mongrel-mysql-osx
They’ve done a good job of keeping it up to date, but one problem I noticed is that the MySQL gem instructions don’t work anymore. When the article was first written, it contained steps to remedy a minor installation problem. However, enough users reported that the problem no longer existed so it was removed.
Today, I encountered that problem again, and thought I’d share the solution. If you’re getting an error when you do
First, locate your installation of MySQL using
You need three libraries:
These should all be located within your mysql base folder.
For example, if MySQL is installed by Macports, the default location would be
So you’d change the paths accordingly:
sudo gem install mysql -- --with-mysql-include=/opt/local/include/mysql5 --with-mysql-lib=/opt/local/lib/mysql5 --with-mysql config=/opt/local/lib/mysql5/bin/mysql_config
This solution seems to get things rolling. Thanks much to crookshanks on IRC for the fix. Really, if you’re not participating in the IRC channels for Rails (#rubyonrails on irc.freenode.net) you’re missing out on some good discussions.
The rest of this article is most likely not relevant anymore.,/b>
You’ll need to do the following to fix it.
First, look at where the gem says it’s left its files.
Gem files will remain installed in /usr/local/lib/ruby/gems/1.8/gems/mysql-2.7 for inspection.
So in my case, I’ll do
Then I’ll edit the file ‘mysql.c’ in that folder and add one line at the top of the file:
#define ulong unsigned long
Then, I just run
sudo make sudo make install
The original fix for this comes from
http://jlaine.net/2006/10/3/installing-ruby-mysql-driver-on-os-x but the instructions there are a little backwards. I hope this solution will help others having a similar problem.