FAIL: sudo gem install mysql (Fixed)

The other day I had an issue with ruby and so I went to google to fine a fix…. I laughed when the second result was my own blog. 🙂

I figured it wouldn’t hurt to save me some time next time I run into the OS Xnightmare with the mysql gem so here is what happened and what I did to fix it.

After running “sudo gem install mysql” I got the following errors:

/usr/local/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

As usual I looked into the mkmf.log found in the gem directory and saw a bunch of these:

"gcc -o conftest -I. -I/usr/local/lib/ruby/1.8/i686-darwin9.6.2 -I. -I/usr/local/include   -D_XOPEN_SOURCE=1  -fno-common -pipe -fno-common conftest.c  -L. -L/usr/local/lib -L/usr
/local/lib -L.      -lruby-static -lmysqlclient  -lpthread -ldl -lobjc  " 
ld: library not found for -lmysqlclient
collect2: ld returned 1 exit status
checked program was:
/* begin */
1: /*top*/
2: int main() { return 0; }
3: int t() { mysql_query(); return 0; }
/* end */

So here is what I did to fix it:

sudo ln -s /usr/local/mysql/include /usr/local/include/mysql
sudo ln -s /usr/local/mysql/lib /usr/local/lib/mysql

[heppy /usr/local/lib/ruby/gems/1.8/gems/mysql-2.7 64]$ sudo gem install mysql
Building native extensions.  This could take a while...
Successfully installed mysql-2.7
1 gem installed
Installing ri documentation for mysql-2.7...



4 responses to “FAIL: sudo gem install mysql (Fixed)”

  1. Matt says :

    I ran into a similar issue, but after I reinstall and try a rake db:migrate from my app’s directory I get the following error:

    !!! The bundled mysql.rb driver has been removed from Rails 2.2. Please install the mysql gem and try again: gem install mysql.
    rake aborted!
    dlsym(0x158ca40, Init_mysql): symbol not found – /usr/local/lib/ruby/gems/1.8/gems/mysql-2.7/lib/mysql.bundle

    Could it be because I am using the 64-bit mysql? I have seen some comments about that. My database.yml has been configured. What am I missing?

    Thanks, Matt

  2. Avram says :

    Thank you Thank you Thank you!!!!!!

    I spent about 2 days struggling with this issue. Google search after Google search just kept turning up the same solutions on different blogs… “just add –with-mysql-config=/usr/local/bin/mysql..” or “put sudo env ARCHFLAGS=’-arch i386′ in front of the gem command”, etc.

    Finally, creating those sym-links like you did before calling the following command did the trick:
    sudo env ARCHFLAGS=’-arch i386′ gem install mysql — –with-mysql-dir=/usr/local/mysql –with-mysql-lib=/usr/local/mysql/lib/

    I don’t understand why this was so difficult – who’s to blame here? Apple? MySQL? whoever wrote or maintains that mysql gem? Maybe it’s a combination of all three – I just hope someone figures out a way to make it ***just work*** so we don’t drive anyone else insane in the future. 🙂

  3. Zed says :

    Another thank you, thank you, this time from a Solaris user. I got there without symlinks with:

    @ARCHFLAGS=’-arch sparc’ gem install mysql — –with-mysql-dir=/usr/local/mysql –with-mysql-lib=/usr/local/mysql/lib/mysql –with-mysql-include=/usr/local/mysql/include/mysql@

    Using with-mysql-config=/usr/local/bin/mysql_config didn’t work.

  4. Paul Hepworth says :

    Glad I was able to help you guys.

Leave a Reply

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

You are commenting using your 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: