LoginSignup
4
4

More than 3 years have passed since last update.

Rails6(MySQL、Ubuntu環境、Cloud9)

Last updated at Posted at 2020-11-02

1 railsのgemをインストール

#rails6の場合
gem install rails -v 6.0.1
#rails5.2の場合
gem install rails -v 5.2.1

2 MySQLセッティング(Cloud9ではMySQL自体はデフォルトでインストールされている)

#これをインストールしておかないと、mysql2 gemのインストールでエラーになります。
$ sudo apt-get install libmysqld-dev

3 Rails new


$ rails new appname -d mysql

4 MySQL Account を作る

$ sudo mysql -u root   #rootユーザーでログイン
$ mysql> create user 'ユーザー名' identified by 'パスワード';  #ユーザー作成
$ mysql> grant all on *.* to 'ユーザー名';  #ALL権限付与

#作成したユーザーの確認は下記コマンド
$ mysql> select User,Host from mysql.user;

5 config/database.ymlの編集

default: &default
  adapter: mysql2
  encoding: unicode
  pool: 5
  # 以下、3行追加
  username: <username> # 設定したMySQL Accountと同一のもの
  password: <password> # 設定したMySQL Accountと同一のもの
  host: localhost

development:
  <<: *default
  database: appname_development # appnameのところは、rails new時のappnameになっているはずです。
test:
  <<: *default
  database: appname_test # appnameのところは、rails new時のappnameになっているはずです。

6 rails db:createでデータベースを作成&webpackerインストール

$ cd appname
$ rails db:create

#rails5の場合は不要
$ source <(curl -sL https://cdn.learnenough.com/yarn_install)
$ yarn install --check-files
$ rails webpacker:install

#config/enviroments/development.rb
config.hosts.clear
4
4
0

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
4
4