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
Derek wrote:
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
Posted 19 Nov 2007 at 12:15 pm ¶
Rich Brant wrote:
Derek, so glad it helped you out!
Posted 19 Nov 2007 at 1:11 pm ¶