Error Connecting to MySQL using Ruby on Rails in Linux – and its Solution

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 ‘sudo gem update --system‘. I started the inbuilt server and tried to open a page – and to my surprise, I found that Rails is having trouble connecting to the MySQL server. It was apparent that the mysql gem was missing. So I tried to install it using the command ‘sudo gem install mysql‘. That failed too – this is the error I got…

Thanks a lot! I’ve been Googling for the past couple of hours and all I got were sources from either Mac OSX or Windows systems. Finally, I found your article which targets CentOS systems.

I wasn’t able to install mysql-devel and ruby-mysql from the base repository, though. In my case, I had to get mysql-devel from the Remi repo, which is where I also got my MySQL 5.1.50 installation. The latest MySQL from the base repo at this time was 5.0.xx. I got ruby-mysql from the EPEL repo.