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
{ 1 trackback }
{ 9 comments… read them below or add one }
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
Derek, so glad it helped you out!
Thanks dude
Whew! You wouldn’t believe how many pages have been written on this. Yours is the most current, I guess,
Thank you!
Ron
Bingo! Thanks, man.
Thanks Brow!
Thankyou thankyou thankyou!!! The world is a better place with you in it!
If you’re using MySQL 5.0:
sudo apt-get install libmysqlclient15-dev
@li: thanks, exactly what i needed. :)