LoginSignup
0
2

More than 3 years have passed since last update.

Vagrant+Rails6+MySQL 開発環境構築

Posted at

はじめに

MySQLインストール

MySQLインストール

# MySQLのyumリポジトリから、最新のCentOS7用のリポジトリを追加
$ sudo yum -y install http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm

# MySQL Community Serverのインストール
$ sudo yum -y install mysql-community-server

# インストールできたか確認
$ mysqld --version

起動・自動起動設定

# vagrant起動時に自動で起動するように設定
$ sudo systemctl enable mysqld.service
# 自動起動が設定できているか確認
$ sudo systemctl list-unit-files -t service | grep mysqld
mysqld.service                                enabled

# MySQL起動
$ sudo systemctl start mysqld.service

MySQL初期設定

# rootユーザーにパスワードを設定(今回はrootパスワードを設定)
$ /usr/bin/mysqladmin -u root password 'root'

# セキュリティー関連の初期設定(ここでパスワードを聞かれると'root'とする)
$ mysql_secure_installation

文字コード追記

/etc/my.cnfをエディタで開いてUTF-8の文字コードを追記する

vi /etc/my.conf
/etc/my.conf
# 一番下に次の2行を追加する
character_set_server=utf8
skip-character-set-client-handshake

Railsで必要なパッケージをインストール

# RailsでMySQLを使用するためのパッケージをインストール
$ sudo yum install mysql-devel

プロジェクト作成まで進んだらconfigファイルの編集

プロジェクトディレクトリ
vi /config/database.yml
/conf/database.yml
# パスワードを追記
default: &default
  adapter: mysql2
  encoding: utf8mb4
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  username: root
- password:
+ password: root
  socket: /var/lib/mysql/mysql.sock

接続する場合

# 接続
$ mysql -u root -p
0
2
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
0
2