LoginSignup
7

More than 5 years have passed since last update.

Cloud 9上で既存 MySQL with Rails 環境の設定

Last updated at Posted at 2016-02-16

chromebookで開発を行っていますが、その際にクラウドのIDEを利用しています。
この類のサービスではCloud 9Nitrousが有名ですが、私はコストを掛けずに利用したいので試用期間のないCloud 9を利用しています。
データベースにMySQLを利用した既存のRailsアプリ環境の構築を行った際に少々手間取ったので、最終的に私が行ったことをメモしておきます。

手順

MySQLをインストール

console
$ gem install mysql2

database.ymlの設定

config/database.yml
development:
  adapter: mysql2
  encoding: utf8
  database: c9
  username: <%=ENV['C9_USER']%>
  host: <%=ENV['IP']%>

MySQLを起動

console
$ mysql-ctl start
=>Installing MySQL
=> * Stopping MySQL database server mysqld
=>   ...done.
=> * Starting MySQL database server mysqld
=>   ...done.
=> * Checking for tables which need an upgrade, are corrupt or were not closed cleanly.
=>
=>MySQL 5.5 database added.  Please make note of these credentials:
=>
=>       Root User: user_name
=>   Database Name: c9
=>
=> * Starting MySQL database server mysqld
=>   ...done.

structure.sqlを読み込む

私が構築したアプリはsqlでスキーマ情報を管理していました。
そこで、db/structure.sqlを読み込みます。

console
$ bundle exec rake db:structure:load

データベースに既存のデータを取り込む

MySQLを起動した際に、c9というデータベースが追加されています。
このデータベースは空の状態ですから、既存のデータベースを取り込む必要があります。
元データはshared/database.sqlにあったので、以下のコマンドを実行します。

console
$ mysql -uroot -p c9 < shared/database.sql

マイグレート

console
$ bundle exec rake db:migrate

以上になります。

参考リンク

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7