Recently we upgraded our development environments to rails 2.2.2. All was good until we realized that they had removed the bundled mysql connection library and we needed to install the gem on our OSX boxes.
After running the install command:
sudo gem install mysql
We received the following errors:
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
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
*** 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.
etc...
Google searches revealed so good solutions but none of them worked. The most popular methods required us to change the mysql.c file, and that is not something I general like to mess with. Given our reluctance to start messing with header files, we keep looking for they combination of command line options that would work knowing we always had the other posts to fall back on.
Finally we came up with a command that worked without having to modify the mysql.c file. If you are running into problems getting the gem installed and you don't want to mess with the mysql.c file please try the command below. It worked for us:
sudo gem install mysql -- --with-mysql-lib=/usr/local/mysql/lib --with-mysql-include=/usr/local/mysql/include --with-mysql-dir=/usr/local/mysql --with-mysql-config=/usr/local/mysql/bin/mysql_config