I swore I wouldn't

Icon

Oh no, I'm blogging now?

Installing MySQL gem on OS X


I encountered the following error when installing the mysql gem on a shiny new Macbook Pro running OS X Leopard.

Note: I have ~/.gem set as my GEM_HOME and GEM_PATH to avoid needing to sudo


> gem install mysql
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
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lm... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lz... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lsocket... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lnsl... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lmygcc... no
checking for mysql_query() in -lmysqlclient... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.

The workaround was fairly simple. Since I had installed MySQL from source the situation was resolved with a few command line options:


> export ARCHFLAGS="-arch x86_64"
> gem install mysql -- \
--with-mysql-dir=/usr/local/mysql \
--with-mysql-lib=/usr/local/mysql/lib \
--with-mysql-include=/usr/local/mysql/include \
--with-mysql-config=/usr/local/mysql/bin/mysql_config

Building native extensions. This could take a while...
Successfully installed mysql-2.8.1
1 gem installed

Installing MySQL from source on OS X

While MAMP has proven to be very convenient for doing local development, not having the MySQL header files around sometimes causes difficulty when it comes time to install/compile something that needs those header files to be in place.

Getting Ready
I always set up a src directory under my user account for these installations.

> cd ~
> mkdir src
> cd src

Download MySQL Community Edition
At the time of this writing, it could be found at http://mysql.mirrors.hoobly.com/Downloads/MySQL-5.1/mysql-5.1.45.tar.gz

Download this file into your src directory.

> curl -O http://mysql.mirrors.hoobly.com/Downloads/MySQL-5.1/mysql-5.1.45.tar.gz

Untar, configure, and install

> tar -xvzf mysql-5.1.45.tar.gz
> cd mysql-5.1.45
> ./configure --prefix=/usr/local/mysql --with-extra-charsets=complex \
--enable-thread-safe-client --enable-local-infile --enable-shared \
--with-plugins=innobase

> make
> sudo make install

> cd /usr/local/mysql
> sudo ./bin/mysql_install_db --user=mysql
> sudo chown -R mysql ./var
> cd ..

MAMP specific issue

Given that I had installed MAMP previously, I had modified my /etc/my.cnf to specify that the mysql.sock was located in /Applications/MAMP/tmp/mysql/mysql.sock. I modified this line to point to /usr/local/mysql/var/mysql.sock, and then set the sticky bit on the var directory.

> chmod 1777 /usr/local/mysql/var

There are other steps that can be added so that mysqld launches on startup, but I prefer to start it manually when it is needed.

Installing django with MySQL on OS X

I am experimenting with the django web-framework for a few projects at work.  I do the majority of my work in PHP or Java, but occasionally I like to play with Ruby on Rails, and decided that django deserved to have a look as well.

The first step in this process is to get django and the various components installed.

  • Python
  • EasyTools
  • MySql
  • MySqlDB
  • Django

Read the rest of this entry »