Getting the mysql gem installed on Ubuntu
If you’re like me, you’ve gotten the ‘MySQL lost connection’ errors when running rails apps on Ubunutu. And if you’ve tried to apply the common fix - installing the mysql gem - you might not have been able to and have seen an error such as:
ERROR: While executing gem … (Gem::Installer::ExtensionBuildError)
ERROR: Failed to build gem native extension.
The problem is that you need the MySQL development headers in order to get the ruby gem to compile…sooo, you need to install this first (gem install mysql-dev won’t work):
apt-get install libmysqlclient12-dev
Then run:
gem install mysql
Select the right gem and you should be all set.
UPDATE:
if you see the error:
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 ***
try:
sudo gem install mysql — –with-mysql-config
Category: Ruby/Rails, Ubuntu
November 19th, 2007 at 12:15 pm
Thank you so much for this! I had this infuriating problem, which started I thought would be as easy to solve as running apt-get for the mysql server and client packages. Nope — and all I could find on google was how to fix it on Mac OS X. All I needed was to do the following:
> sudo apt-get install libmysqlclient15-dev
> sudo gem install mysql
November 19th, 2007 at 1:11 pm
Derek, so glad it helped you out!
March 2nd, 2009 at 9:23 am
Thanks dude
April 25th, 2009 at 12:55 pm
Whew! You wouldn’t believe how many pages have been written on this. Yours is the most current, I guess,
Thank you!
Ron
May 6th, 2009 at 6:16 pm
[...] le gem MySQL par contre, j’ai du faire une manip spéciale [...]
May 29th, 2009 at 11:30 am
Bingo! Thanks, man.
June 19th, 2009 at 9:54 am
Thanks Brow!
June 23rd, 2009 at 10:00 am
Thankyou thankyou thankyou!!! The world is a better place with you in it!