Installing Mysql gem on CentOS
Migrating from Debian to CentOS was certainly not pleasant one. But slowly I am getting used to yum (I still miss my apt). Recently I faced an issue installing mysql gem. Here is short description of problem followed by solution.
[root@VMVSOCT02 /]# gem install mysql
Need to update 0 gems from http://gems.rubyforge.org
complete
Select which gem to install for your platform (i386-linux)
1. mysql 2.7.3 (mswin32)
2. mysql 2.7.1 (mswin32)
3. mysql 2.7 (ruby)
4. mysql 2.6 (ruby)
5. Skip this gem
6. Cancel installation
> 3
Building native extensions. This could take a while…
ERROR: While executing gem … (Gem::Installer::ExtensionBuildError)
ERROR: Failed to build gem native extension.
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
*** 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
Installation Steps
1. yum uninstall mysql
2. yum install mysql
3. yum install mysql-devel (to install development libraries, For Debian, Knoppix, Buildix user apt-get install libmysqlclient15-dev)
4. gem install mysql
[root@VMVSOCT02 /]# gem install mysql
Need to update 1 gems from http://gems.rubyforge.org
.
complete
Select which gem to install for your platform (i386-linux)
1. mysql 2.7.3 (mswin32)
2. mysql 2.7.1 (mswin32)
3. mysql 2.7 (ruby)
4. mysql 2.6 (ruby)
5. Skip this gem
6. Cancel installation
> 3
Building native extensions. This could take a while…
Successfully installed mysql-2.7
Create database users
octopus/octopus
grant permission on octopus_development, octopus_test

Hi,
I follow your step but still get the same error message. Any suggestion?
Did you check your mkmf.log file. This error is usually caused by not having all the dependencies fulfilled or have a wrong version.
@winson: try doing this on a fresh CentOS v5 base install:
$ sudo yum install gcc mysql mysql-devel
$ sudo gem install mysql -- \
--with-mysql-include=/usr/include/mysql \
--with-mysql-lib=/usr/lib/mysql
@nippleequality – your suggestion fixed my problem too! Thanks.
@nippleequality – thank you so much! Everywhere I looked for this answer, people only gave the lib option, I never even thought to use the include as well – totally solved my problem!
I had this problem, and I found out the solution here:
http://forums.mysql.com/read.php?116,178217,201272#msg-201272
I just needed to install libmysqlclient15-dev
nippleequality – you rock very hard. I could not get this bugger installed on CentOS at all – till I tried your instructions. Major respect!
@nippleequality – Yet another thank you! Worked perfectly.
one more “thank you” to @nippleequality
Thanks, big help.
May seem obvious to some, but if you’ve installed the 64-bit package, you need to install the gem with –with-mysql-lib=/usr/lib64/mysql instead
major thanks.
[...] Install MySQL Gem Faild for me, so i found here the solution: mysql gem on centos [...]
CentOS + VirtualBox + Ruby on Rails « pure tec said this on February 7, 2009 at 9:42 am |
thanks…. !
centos ovh plesk
[...] Sudo gem install mysql, mysql-devel problems in CentOs By torsd Installing Mysql gem on CentOS [...]
Sudo gem install mysql, mysql-devel problems in CentOs « Ruby on Rails UI Designer | Ruby on Rails Frontend Developer said this on February 2, 2010 at 7:55 pm |