gem install mysql OS X

After having trouble installing mysql support for python, I ran into similar problems with ruby. To fix, first I installed a new version of MySQL from mysql.com. I'm not sure if this is necessary since OS X comes with MySQL but I don't have a second box to test with. After running the install, pick one of the lines below that matches the version you installed.

MySQL x86:

sudo env ARCHFLAGS="-arch i386" gem install mysql -- \
--with-mysql-include=/usr/local/mysql/include \
--with-mysql-lib=/usr/local/mysql/lib

MySQL x86_64:

sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- \
--with-mysql-include=/usr/local/mysql/include \
--with-mysql-lib=/usr/local/mysql/lib

* I had problems using the x86_64 version because ruby is only compiled as 32-bit

Comments

>env ARCHFLAGS="-arch i386"
>gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config

i spent 4 hours trying to find this answer. I ran the commands for PPC

sudo env ARCHFLAGS="-arch ppc"

and

sudo gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config

and it worked!!! THANK YOU!!!!!

for all those googling this .. i got the following error.. supplying lib directories and mysql directories didn't work...

g4-15:mysql-2.7 user$ 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
*** 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.

thanks again.
andy.

Thanks man, followed all the steps and it worked.

NOTE: If you're using RVM, drop the "sudo".

Rob