Apache2.4+passenger5でrails4.2を動かす
o_wani
owani.net#stay.hungry
すでに作成しているrailsのプロジェクトのデータベースをsqlite
からmysql
に変更する。
1.$ sudo yum install mysql-server mysql-devel
1.$ sudo /etc/init.d/mysql start
1.$ mysql -u root -p
2.Enter password:
3.Welcome to the MySQL monitor. Commands end with ; or \g.
db_development
db_test
db_production
1.mysql> CREATE DATABASE db_development DEFAULT CHARACTER SET utf8;
2.Query OK, 1 row affected (0.00 sec)
3.
4.mysql> CREATE DATABASE db_test DEFAULT CHARACTER SET utf8;
5.Query OK, 1 row affected (0.00 sec)
6.
7.mysql> CREATE DATABASE db_production DEFAULT CHARACTER SET utf8;
8.Query OK, 1 row affected (0.00 sec)
db_login_user
を作成する。
1.mysql> GRANT ALL PRIVILEGES ON db_development.* TO db_login_user@localhost IDENTIFIED BY 'password' WITH GRANT OPTION;
2.Query OK, 0 rows affected (0.00 sec)
3.
4.mysql> GRANT ALL PRIVILEGES ON db_test.* TO db_login_user@localhost IDENTIFIED BY 'password' WITH GRANT OPTION;
5.Query OK, 0 rows affected (0.00 sec)
6.
7.mysql> GRANT ALL PRIVILEGES ON db_production.* TO db_login_user@localhost IDENTIFIED BY 'password' WITH GRANT OPTION;
8.Query OK, 0 rows affected (0.00 sec)
sqlite用の設定になっているので、MySQL用に書き換えます。
config/database.yml
1.# MySQL. Versions 5.0+ are recommended.
2.#
3.# Install the MYSQL driver
4.# gem install mysql2
5.#
6.# Ensure the MySQL gem is defined in your Gemfile
7.# gem 'mysql2'
8.#
9.# And be sure to use new-style password hashing:
10.# http://dev.mysql.com/doc/refman/5.0/en/old-client.html
11.#
12.default: &default
13. adapter: mysql2
14. encoding: utf8
15. reconnect: false
16. pool: 5
17. socket: /var/lib/mysql/mysql.sock
18.
19.development:
20. <<: *default
21. database: db_development
22. username: db_login_user
23. password: password
24.
25.
26.test:
27. <<: *default
28. database: db_test
29. username: db_login_user
30. password: password
31.
32.
33.production:
34. <<: *default
35. database: db_production
36. username: db_login_user
37. password: password
mysqlのライブラリを追加する。
Gemfile
1....
2.gem 'mysql2', '~> 0.3.20'
3....