getting rails 4 up and running with MySQL is a little head ache when compared to the Unix rails environments. In this tutorial I will explain how to set up MySQL server for rails 4 application on windows. The latest MySQL connector creates errors while connecting with rails application. So i recommend you to use 6.0.2 MySQL connector for your rails application.
I assume that you have ruby 2.0 , rails 4 and MySQL server installed on your windows machine.
Setting up the environment variable for MySQL
1. Set up the environment variable for MySQL server, so that you can use the server from the command line. If you do not set up the environment variable you won’t be able to access the MySQL server from the command line.
2. Find out the installation directory for MySQL in the C. The path for the installation directory would look like following path.
C:Program FilesMySQLMySQL Server 5.6bin
3. Now open my computer –> right-click and select properties –>click advanced settings from the left top options –> click environment variables –> scroll down and sect path –> click edit –> append the path to the existing line.
4. Now you will be able to connect to MySQL server from the command line. You can test it by typing the following command in the command line.
mysql -u root -pyour_password
5. next step is to configure the MySQL connector for the rails application to work properly.
6. Download 6.0.2 mysql connector form dev.mysql.com and extract it to the C: folder
7. Now browse to the lib folder from the connector folder and copy the libmysql.dll to the bin folder of your ruby installation. It looks somewhat like this C:RailsInstallerRuby2.0.0bin
8. Now install the MySQL ruby gem using the following command.
gem install mysql --platform=ruby -- --with-mysql-dir="C:/mysql-connector-6.0.2-win32"
9. make sure that you use the correct folder name for the connector.
10. After successful execution of the above command, you can start using your rails application with MySQL.
11. If you have an existing rails application , you can execute the following command to make changes to your database.
bundle exec rake db:migrate
Leave a comment for queries.
Latest posts by Dhipu Mathew (see all)
- 5 Best Udemy Web Development Courses For Beginners - June 9, 2015
- How To Install and Configure Django Framework on Windows - February 23, 2015
- WordPress Tutorial : How to Install WordPress on Windows Computer - November 14, 2014