Ruby, Rails, Cygwin, MySQL
There are many teams and individuals that run Ruby on Rails under Cygwin although it is a little slower than the native Windows or the much faster Linux installations. One of the problems those folks come across is with talking to mysql. After starting ./script/server and trying to connect, Rails throws out an error looking for a unix socket: Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ ‘/tmp/mysql.sock’. But as most guess, mysql would have been already been running as a Windows Service.
The solution is to simply replace all ‘localhost’ occurences to ‘127.0.0.1’ because then, Rails will be forced to use Windows TCP/IP sockets instead of a unix socket. And remember to restart your Rails server (WEBRick/Apache/Lighttp).
The simplest order of installing Rails under Cygwin on an all new Windows box would be:
- Make sure you have uninstalled all copies of RubyOneClick Installer.
- Install Cygwin and a shell such as bash (or xterm if you like Cygwin-X)
- Install Ruby from the cygwin setup under ‘Devel’ Category.
- Have MySQL installed as a Windows Service (or make one from mysql source packages)
- Download RubyGems, extract it to a temporary directory (c:/cygwin/tmp/ or c:/temp/ if you like)
- Open bash and navigate to that directory using “cd” commands, and type: ruby setup.rb
- When done, type: gem install rails --include-dependencies
- Then, type: gem install mysql and in the prompt, pick latest mswin32 if you installed mysql as a service or latest ruby version if you built it from the source.
- Create a sample rails application at /tmp/railstest/ by typing: rails /tmp/railstest
- and finally edit ./config/database.yml file to use 127.0.0.1 rather than localhost
The entire process along with the time taken to gather necessary knowledge etc (if you wish to) would take 2 hours but if you follow these instructions blindly it shouldn’t take more than 30-45 minutes on a quite fast machine.
As for an editor, download PSPad and turn on Ruby On Rails highlighter under Settings-->Highlighters Settings and pick “Ruby on Rails” and “Ruby” for any two unassigned slots.










Recent Comments