Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I install the Rails MySQL adapter?

There's not much more to my question than that. gem install mysql doesn't work and I haven't found anything by Googling.

When I try gem install mysql2, this is what I get. I don't know what to do now.

jason@buster:~/projects/mcif-rails$ gem install mysql2
Building native extensions.  This could take a while...
ERROR:  Error installing mysql2:
        ERROR: Failed to build gem native extension.

/home/jason/.rvm/rubies/ruby-1.9.2-p136/bin/ruby extconf.rb
checking for rb_thread_blocking_region()... yes
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... yes
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.

Provided configuration options:
        --with-opt-dir
        --without-opt-dir
        --with-opt-include
        --without-opt-include=${opt-dir}/include
        --with-opt-lib
        --without-opt-lib=${opt-dir}/lib
        --with-make-prog
        --without-make-prog
        --srcdir=.
        --curdir
        --ruby=/home/jason/.rvm/rubies/ruby-1.9.2-p136/bin/ruby
        --with-mysql-config
        --without-mysql-config
        --with-mysql-dir
        --without-mysql-dir
        --with-mysql-include
        --without-mysql-include=${mysql-dir}/include
        --with-mysql-lib
        --without-mysql-lib=${mysql-dir}/lib
        --with-mysqlclientlib
        --without-mysqlclientlib
        --with-mlib
        --without-mlib
        --with-mysqlclientlib
        --without-mysqlclientlib
        --with-zlib
        --without-zlib
        --with-mysqlclientlib
        --without-mysqlclientlib
        --with-socketlib
        --without-socketlib
        --with-mysqlclientlib
        --without-mysqlclientlib
        --with-nsllib
        --without-nsllib
        --with-mysqlclientlib
        --without-mysqlclientlib
        --with-mygcclib
        --without-mygcclib
        --with-mysqlclientlib
        --without-mysqlclientlib


Gem files will remain installed in /home/jason/.rvm/gems/ruby-1.9.2-p136/gems/mysql2-0.2.6 for inspection.
Results logged to /home/jason/.rvm/gems/ruby-1.9.2-p136/gems/mysql2-0.2.6/ext/mysql2/gem_make.out
like image 526
Jason Swett Avatar asked Jan 04 '11 18:01

Jason Swett


2 Answers

It looks like you still need to install MySQL's development libraries. These are required for the gem to build successfully on your system.

[Edit] Seems the RoR Wiki is no longer available. But, Ubuntu has offered their own walkthrough which suggests:

sudo apt-get install mysql-server mysql-client
sudo apt-get install libmysql-ruby libmysqlclient-dev
sudo gem install mysql

See http://wiki.rubyonrails.org/database-support/mysql#installation for more detail.

Example: Ubuntu

sudo apt-get install mysql-server mysql-server-5.0 libmysqlclient15off \
    libmysqlclient15-dev mysql-client-5.0 mysql-common

sudo apt-get install libmysql++-dev

sudo gem install mysql

like image 177
Jonathan Lonowski Avatar answered Sep 30 '22 02:09

Jonathan Lonowski


I'll just leave this here:

I ran into a similar problem, then realized I couldn't install the mysql2 gem without having MySQL installed on my development machine (even though I'm only using the mysql2 gem to connect to a remote MySQL server).

::forehead slap::

brew install mysql

then, in my Gemfile:

gem 'mysql2', '~> 0.3.11'

followed by a quick

bundle install

Success!

like image 44
jasonmklug Avatar answered Sep 30 '22 03:09

jasonmklug