Setting up MySQL from WAMPServer to be used alongside with Ruby on Rails in Windows Vista

Dear Readers,

Recently, I got into the project that will be using Ruby on Rails as its platform. Okay, let's get through to the setting up environment process.

My system list:
  • Windows Vista Ultimate SP 1
  • WAMPServer consists of Apache, MySql, PHP stack. (We will only make use of its MySQL)
1. First get the Ruby if you haven't yet here: http://www.ruby-lang.org/en/downloads/
I'm using the latest stable one (Ruby 1.9.2-p136)
2. Find your download and click the installer. For your convenience, don't forget to add the Ruby to the PATH in system's environment variables by clicking 'add to path' section. Otherwise, you have to add the Ruby.exe to the PATH manually.
3. After the ruby installation completed, run the command prompt and check if you can use command ruby by typing it.
4. Ruby 1.9.2 doesn't seem support command gem update --system. It always draws error message. I dunno any workaround on this problem. But, if you use older version such 1.8.6, then it should be fine. 
5. Okay, you have it worked then you should install the required gem (library) for rails by typing gem install rails. If you success, then at this step you have completed setting up the rails environment.

Now, we move to setting up MySQL database used in WAMPServer. Maybe some of you questioning why use WAMPServer's MySQL stack? The motivation behind this is because I'm heavily developing PHP using WAMPServer and it seems redundant to install a new MySQL database so why not to make use the installed MySQL database on WAMPServer. Save space. :)

6. Okay, start the WampServer. Make sure to turn off the Apache server's service and let MySQL service run and make sure it is running. Find the WAMPServer icon on the taskbar > MySQL > My.ini. Open and edit it. Add bind-address = 127.0.0.1 under the socket section. This will tell MySQL server to bind with local apps.
7. Open the MySQL console and login to it. By default, there is no password for root user so you can leave it empty when being prompted for password. Create the database for your rails application by using this sql statement: create database `<database name>`;. Replace <database name> with a name for your application's database. For example: rails_test
8. Install the Ruby gems for MySQL by typing gem install mysql

Now, we will create a new Rails project. With command prompt, browse to your pre-defined rails project folder. For example, My project folder is in my document folder and under programming sub folder (my documents > programming > myrailsproject).
9. Create a new project by typing command: rails new <project_name> -d mysql. -d mysql option is required to specify the DBMS that we used for the project. By default, it will use sqlite.
10. Inspect the project folder (the project's name is the same with the <project_name> you specified when create a project in the step before). Then inspect the config folder. Open and edit database.yml. Please make sure the database name is the same with the database name on MySQL. (You can make database entry for the test and production too in MySQL before and bind each in database.yml configuration)
At this step you have configured the WAMPServer's MySQL to be used with Ruby on Rails Project. :) 

Comments (0)

Leave a comment...