Thursday, August 20, 2009

How to "gem install mysql" ?

If you trying to install mysql gem, and you are not able to install.
-----------------------------------------------------
gem install mysql
Building native extensions. This could take a while...
ERROR: Error installing mysql:
ERROR: Failed to build gem native extension.

/usr/local/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... yes
checking for mysql_query() in -lmysqlclient... no
-----------------------------------------------------

Resolution :


cd /usr/local/lib/ruby/gems/1.8/gems/mysql-2.7/ && ruby extconf.rb --with-mysql-config --with-mysql-include

o/p:
checking for mysql_ssl_set()... yes
checking for mysql.h... yes
creating Makefile
[root@localhost:/usr/local/lib/ruby/gems/1.8/gems/mysql-2.7] make
gcc -I. -I. -I/usr/local/lib/ruby/1.8/x86_64-linux -I. -DHAVE_MYSQL_SSL_SET -DHAVE_MYSQL_H -I/usr/include/mysql -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -fno-strict-aliasing -fwrapv -fPIC -g -O2 -c mysql.c
gcc -shared -o mysql.so mysql.o -L. -L/usr/local/lib -Wl,-R/usr/local/lib -L. -rdynamic -Wl,-export-dynamic -L/usr/lib64/mysql -lmysqlclient -lz -lcrypt -lnsl -lm -L/usr/lib64 -lssl -lcrypto -ldl -lcrypt -lm -lc

make install
o/p:/usr/bin/install -c -m 0755 mysql.so /usr/local/lib/ruby/site_ruby/1.8/x86_64-linux

[root@localhost rails
]# irb

irb(main):001:0> require 'rubygems'
=> true
irb(main):002:0> require 'mysql'
=> true
irb(main):003:0> quit

Cool Done.! It may possible that mysql gem is not in gem list.