LoginSignup
1
1

More than 5 years have passed since last update.

新しくRuby on Railsでアプリ作成したらMySQL2周りでエラった時の解消方法

Posted at

第1のエラー

まずは、

rails new app_name -d mysql

でDBをMySQLに指定してアプリを作成した。

で、

rake db:create

したら以下のエラー出た。

Specified 'mysql2' for database adapter, but the gem is not loaded. Add `gem 'mysql2'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord).

いやいや、Gemfileにちゃんとgem 'mysql2'って書いてますから。

第1のエラー解決法

いろいろ調べたらバージョンを0.3.20にすれば良いという人がいたのでそうしてみた。

gem 'mysql2', '~> 0.3.20'

で再度

bundle install
rake db:create

したらエラーが変わった。

第2のエラー

次はこんなエラー出た。

#<Mysql2::Error: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)>

MySQLサーバー立ち上がってないのかな?と推測した。

第2のエラー解決法

mysql.server start

ってやったら無事 rake db:create できた。

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