<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Bin-Blog &#187; troubleshoot</title>
	<atom:link href="http://www.bin-co.com/blog/tag/troubleshoot/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bin-co.com/blog</link>
	<description>Learn about the latest in Web Development - as soon as I do.</description>
	<lastBuildDate>Tue, 13 Oct 2009 18:55:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Error Connecting to MySQL using Ruby on Rails in Linux &#8211; and its Solution</title>
		<link>http://www.bin-co.com/blog/2009/04/error-connection-mysql-ruby-rails-linux-solution/</link>
		<comments>http://www.bin-co.com/blog/2009/04/error-connection-mysql-ruby-rails-linux-solution/#comments</comments>
		<pubDate>Fri, 03 Apr 2009 18:22:52 +0000</pubDate>
		<dc:creator>Binny V A</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[error]]></category>
		<category><![CDATA[gem]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[ror]]></category>
		<category><![CDATA[troubleshoot]]></category>

		<guid isPermaLink="false">http://www.bin-co.com/blog/?p=249</guid>
		<description><![CDATA[I am currently working on a new Rails project. Its been a while since I worked with rails - so I updated Rails using the command '<code>sudo gem update --system</code>'. I started the inbuilt server and tried to open a page - and to my surprise, I found that <strong class="highlight">Rails is having trouble connecting to the MySQL</strong> server. It was apparent that the <strong class="highlight">mysql gem was missing</strong>. So I tried to install it using the command '<code>sudo gem install mysql</code>'. That failed too - this is the error I got...]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.bin-co.com/blog/wp-content/uploads/2008/05/ruby_logo.gif" alt="Ruby Logo" title="Ruby Logo" width="105" height="109" class="alignnone size-full wp-image-105 intro" align="right" /></p>
<p class="intro">I am currently working on a new Rails project. Its been a while since I worked with rails &#8211; so I updated Rails using the command &#8216;<code>sudo gem update --system</code>&#8216;. I started the inbuilt server and tried to open a page &#8211; and to my surprise, I found that <strong class="highlight">Rails is having trouble connecting to the MySQL</strong> server. It was apparent that the <strong class="highlight">mysql gem was missing</strong>. So I tried to install it using the command &#8216;<code>sudo gem install mysql</code>&#8216;. That failed too &#8211; this is the error I got&#8230;</p>
<pre>Building native extensions.  This could take a while...
ERROR:  Error installing mysql:
        ERROR: Failed to build gem native extension.

/usr/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
*** 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
        --without-opt-dir
        --with-opt-include
        --without-opt-include=${opt-dir}/include
        --with-opt-lib
        --without-opt-lib=${opt-dir}/lib
        --with-make-prog
        --without-make-prog
        --srcdir=.
        --curdir
        --ruby=/usr/bin/ruby
        --with-mysql-config
        --without-mysql-config
        --with-mysql-dir
        --without-mysql-dir
        --with-mysql-include
        --without-mysql-include=${mysql-dir}/include
        --with-mysql-lib
        --without-mysql-lib=${mysql-dir}/lib
        --with-mysqlclientlib
        --without-mysqlclientlib
        --with-mlib
        --without-mlib
        --with-mysqlclientlib
        --without-mysqlclientlib
        --with-zlib
        --without-zlib
        --with-mysqlclientlib
        --without-mysqlclientlib
        --with-socketlib
        --without-socketlib
        --with-mysqlclientlib
        --without-mysqlclientlib
        --with-nsllib
        --without-nsllib
        --with-mysqlclientlib
        --without-mysqlclientlib

Gem files will remain installed in /usr/lib/ruby/gems/1.8/gems/mysql-2.7 for inspection.
Results logged to /usr/lib/ruby/gems/1.8/gems/mysql-2.7/gem_make.out</pre>
<p>After a couple of hours on Google, I managed to fix the issue &#8211; and I am posting the solution here for others who might run into the same problem.</p>
<h2>Install the necessary Libraries</h2>
<p>First, you must <strong class="highlight">install a couple of mysql libraries</strong>(I am assuming that you have MySQL server already installed). If you are on <strong class="highlight">Red Hat/Fedora/CentOS</strong> etc., run the command&#8230;</p>
<pre><code class="cli">sudo yum install ruby-mysql mysql-devel</code></pre>
<p>If you are on <strong class="highlight">Debian/Ubuntu</strong>/etc., run this command&#8230;</p>
<pre><code class="cli">sudo apt-get install libmysqlclient15-dev libmysqlclient15off libmysql-ruby</code></pre>
<h2>Install the gem</h2>
<p>Once the installation is done, enter this <strong class="highlight">command to install mysql gem</strong>&#8230;</p>
<pre><code class="cli">sudo gem install mysql -- --with-mysql-config=/usr/bin/mysql_config</code></pre>
<p>If your mysql_config is not in the standard location, update the command with the right path.</p>
<p>The mysql gem should be installed now. These commands worked for me &#8211; your milage may vary. If you still have trouble, try one of the following links&#8230;</p>
<h2>More Resources</h2>
<ul>
<li><a href="http://rails.aizatto.com/2007/05/19/connecting-to-mysql-using-ruby/">Connecting To MySQL using Ruby</a></li>
<li><a href="http://wiki.rubyonrails.org/database-support/mysql">MySQL =&gt; Rails Wiki</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.bin-co.com/blog/2009/04/error-connection-mysql-ruby-rails-linux-solution/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
