Wednesday, June 1, 2011

Rails With MySQL on Windows

As discussed in previous article, i have used railsinstaller which installed ruby, rails and sqlite3 but not mysql. So i had to install mysql separately. To use mysql database for my application, i modified the database.yml file to use mysql adapter and other required details.
Other thing to be noted is that you shoudl add the following line in your Gemfile
gem 'mysql'

You also need to ensure that you install the mysql gem using the following command
gem install mysql

Then i tried running the rake db:create command which failed showing up an error dialog with the error message as "The program cant start because LIBMYSQL.dll is missing from your computer. Try reinstalling the program to fix the problem.

Many bloggers have blogged that the above error will go away if we copy teh LIBMYSQL.dll from the mysql installation directory to the ruby/bin installation directory.
In my case, since i am using RailsInstaller, i copied to C:\RailsInstaller\Ruby1.8.7\bin
Then i tried rake db:create but i got the following exception 

c:/RailsInstaller/Ruby1.8.7/lib/ruby/1.8/openssl/x509-internal.rb:77: [BUG] Segmentation fault
ruby 1.8.7 (2011-02-18 patchlevel 334) [i386-mingw32]

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.

But to overcome this error, i followed the tips from the following link

which had mentioned to copy the libmysql.dl from the svn repository location of instant rails website

This fixed my problem. Not sure about whats the reason though

Starting Rails Development In Windows

After having spent a couple of days on learning rails development on a Ubuntu vmware OS, i decided to give a try on windows also. Just because i was running Ubuntu vmware OS on windows, the ubuntu was not that responsive for speeding up my development. So i thought of trying my hands on rails development setup in my windows box itself.
For my surprise, things went very smooth because of the latest tools and installers available for windows rails development. Let us see what i installed and what I IDE i installed for rails development. 


Go to this website and download the install kit
http://railsinstaller.org/
This installer will install Ruby, Rails and Git in your machine.
Git is a version control system that is getting more popular in the Rails community as well as in the open source community. Follow the video in the above webpage to create a simple rails applicaton.


You can verify whether the installer successfully installed ruby, rails and git by typing in the following commands in your command line.
ruby -v 
rails -v
git
These commands will provide some meaningful output in the command window.
You can start using a text editor and rails commands to start creating an application.
But i decided to try out the free IDE available (Aptana Studio) for rails development.
Just download the standalone version of the aptana studio for windows from the following location
http://www.aptana.com/products/studio3/download

The aptana studio just works out of box once installed. You can create a rails project using File-> New Rails project and you are set to launch your application by starting :"Run Server" command.


The ruby installer mentioned above doesnt contain mysql. So you might have to install mysql separately. If you install mysql in windows, it might be running as a service. I had installed mysql sometime back. But i had trouble logging into the mysql server. This might be because i was not sure about the password for the 'root' user. You can reset the password for the user 'root' by following steps in the following link.
http://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html