MySQL database

Contrary to SQlite3, Rails cannot create MySQL database directly. In order to create database we first have to start MySQL server. Go to the bin subdirectory of the folder where you have unpacked archive, C:\mysql-5.6.23-win32\bin in my case and start mysqld.exe application. Open new Command Prompt in the same folder, start MySQL client as root user and create database rwinbookdevel:

c:\mysql-5.6.23-win32\bin>mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.23 MySQL Community Server (GPL)

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> create database rwin_book_devel;

If you want to check whether database is created you can use show databases MySQL command:

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| rwin_book_devel    |
| test               |
+--------------------+
5 rows in set (0.00 sec)

With DB server up and running we have to configure Rails application to use MySQL database. Development section of database.yml file inside config directory should look like this:

development:
  adapter: mysql2
  encoding: utf8
  database: rwin_book_devel
  username: root
  password:

In addition we have to alter Gemfile so bundler knows which gems are required by our application. Without removing sqlite3 gem add new line to Gemfile and run bundle install to finish application configuration.

gem 'mysql2'

Before starting database migration we have to do one more thing. Our mysql2 is linked against libmysql.dll shared library and, just as we did with SQlite3, we must put this library in the path so operating system can find it when needed. Now you can migrate database with rake db:migrate task and start rwin_book application.