Rails and Mysql on Windows 7 running smoothly.

Is rails hanging whenever you try and connect to the mysql database?

Well, like many I had some trouble getting this to work.  The problem for me was twofold.  Sometimes, I seem to fall into the rut, that just googling for and answer is the solution.  We do have to THINK as well.  Finally when I engaged my brain, some insight came.

TWO different complicated problems.  When you get ruby to work stand alone, you’re getting close!

1.  Make it work on ruby first.  I really use Ruby on Rails.  Sure I have do to some ruby, but it’s easy to forget that everything you can do in rails can be done directly in ruby.  Here is how to connect to a mysql database in ruby.
require “mysql”

con = Mysql.real_connect(‘localhost’, ‘root’, ‘password’, ‘dealer_nauvou_development’)

res =  con.query(“select * from users;”)

puts res.class

res.each do |row|

puts row.join(” “)

end

 

I tested this by starting “irb” that is interactive ruby, and pasting this code into the window.  If you cannot make this work with your database, then rails will never work.

For me, the problem was that I had multiple mysql gems installed.

gem list mysql

gem uninstall mysql

I had to get rid of ruby-mysql!

gem list mysql

gem install mysql

All was good for me.  This guy,  http://stackoverflow.com/questions/2591794/issues-while-connecting-to-mysql-using-ruby had it almost right.  Another fellow working the same problem.  http://stackoverflow.com/questions/4036130/ruby-mysql-crashing

ruby-mysql did not work for me on windows!

 

2.  So I was feeling good, but rails still did not work.  On to the second problem, making rails work now.

The installed version of libmysql.dll is defective!

Replace your libmysql.dll with InstantRails. one.  The link takes you to a download for the file that you need.  By the time that I got to this point, I had several copies of ruby, happens I’m using 1.9.2, and I replaced the libmysql.dll in the directory c:\ruby\193\bin.

http://stackoverflow.com/questions/1557267/mysql-driver-for-rails-in-windows-7-x64

That link was a perfect answer, so short that I almost did not try it.

Good luck, and remember THINK, don’t just google.

 

Comments are closed.