Question

I have a clean build system as follows

Ubuntu 11.04

Rvm 1.13.5

Ruby 1.9.3p194

Rails 3.2.3

Gem 1.8.24

MySql 5.5.24-1 (installed in /usr/local)

I am trying to install the mysql2 gem (0.3.11) and getting the following problem:

 pal@smurf01:~$ sudo gem install mysql2
   [sudo] password for pal: 
   Building native extensions.  This could take a while...
   ERROR:  Error installing mysql2:
        ERROR: Failed to build gem native extension.

        /usr/local/rvm/rubies/ruby-1.9.3-p194/bin/ruby extconf.rb
   checking for rb_thread_blocking_region()... yes
   checking for rb_wait_for_single_fd()... yes
   checking for mysql.h... yes
   checking for errmsg.h... yes
   checking for mysqld_error.h... yes
   creating Makefile

   make
   compiling client.c
   client.c: In function 'rb_raise_mysql2_error':
   client.c:98:3: warning: ISO C90 forbids mixed declarations and code
   client.c: In function 'rb_mysql_client_socket':
   client.c:590:3: warning: ISO C90 forbids mixed declarations and code
   compiling mysql2_ext.c
   compiling result.c
   linking shared-object mysql2/mysql2.so
   /usr/bin/ld: skipping incompatible /usr/local/mysql/lib/libmysqlclient_r.so when searching for -lmysqlclient_r
   /usr/bin/ld: skipping incompatible /usr/local/mysql/lib/libmysqlclient_r.a when searching for -lmysqlclient_r
   /usr/bin/ld: cannot find -lmysqlclient_r
   collect2: ld returned 1 exit status
   make: *** [mysql2.so] Error 1


   Gem files will remain installed in /usr/local/rvm/gems/ruby-1.9.3-p194/gems/mysql2-0.3.11 for inspection.
   Results logged to /usr/local/rvm/gems/ruby-1.9.3-p194/gems/mysql2-0.3.11/ext/mysql2/gem_make.out
 pal@smurf01:~$

First question: Has anyone got Rails mysql2 running with MySql 5.5.1 on Ubuntu? I have it running on another system with 5.1. The gem description is vague on supported MySql versions.

Second question: Has anyone encountered this problem? I± have battled various library issues with the mysql2 gem over the passed year or so but this seems to be different.

Any assistance is gratefully recieved.

BTW: Reverting back to MySql 5.1 is a valid solution!

Regards

Peter

Was it helpful?

Solution 2

So the problem appears to have been a missing library and some links. Doing the following solved the issue.

Get the new and install the libmysqlclient-dev deb package kindly provided by Nathan Rennie Waldock

 wget http://ppa.launchpad.net/nathan-renniewaldock/ppa/ubuntu/pool/main/m/mysql-5.5/libmysqlclient-dev_5.5.24-1~ppa1~natty_amd64.deb./;l
 dpkg -i libmysqlclient-dev_5.5.24-1~ppa1~natty_amd64.deb

Then create some links that mysql2 needs as it can't seem to follow the mysql path

cd /usr/lib/
ln -s /usr/local/mysql-5.5.24-linux2.6-x86_64/lib/libmysqlclient_r.a .
ln -s /usr/local/mysql-5.5.24-linux2.6-x86_64/lib/libmysqlclient_r.so .
ln -s /usr/local/mysql-5.5.24-linux2.6-x86_64/lib/libmysqlclient_r.so.18 .
ln -s /usr/local/mysql-5.5.24-linux2.6-x86_64/lib/libmysqlclient_r.so.18.0.0 .

Now happily install the mysql2 gem

sudo gem install mysql2
  Fetching: mysql2-0.3.11.gem (100%)
  Building native extensions.  This could take a while...
  Successfully installed mysql2-0.3.11
  1 gem installed
  Installing ri documentation for mysq2l-0.3.11...
  Installing RDoc documentation for mysql2-0.3.11...

OTHER TIPS

Or just apt-get install libmysqlclient-dev and then gem install mysql2

Had the same issue in Ubuntu 12.04 also using the ppa mentioned in the accepted answer. But also there was no libmysqlclient file on my system with _r in the name. Googling around I found out that package builders have started to drop the _r suffix from the files, so that might have happened between 11.10 and 12.04.

Also the paths were a bit different to the once mentioned so these are the symlinks that I had to create:

ln -s /usr/lib/x86_64-linux-gnu/libmysqlclient.a ./libmysqlclient_r.a
ln -s /usr/lib/x86_64-linux-gnu/libmysqlclient.so ./libmysqlclient_r.so
ln -s /usr/lib/x86_64-linux-gnu/libmysqlclient.so.18 ./libmysqlclient_r.so.18
ln -s /usr/lib/x86_64-linux-gnu/libmysqlclient.so.18.0.0 ./libmysqlclient_r.so.18.0.0

I had this problem as well...

I did dpkg -r mysql-devel as when I was trying to do apt-get install libmysqlclient-dev I got an error saying:

Unpacking libmysqlclient-dev (from .../libmysqlclient-dev_5.5.24-0ubuntu0.12.04.1_i386.deb) ... dpkg: error processing /var/cache/apt/archives/libmysqlclient-dev_5.5.24-0ubuntu0.12.04.1_i386.deb (--unpack): trying to overwrite '/usr/bin/mysql_config', which is also in package mysql-devel 5.5.28-2

After doing this, gem install mysql2 worked! yay :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top