MySQL をデータベースとして Windows で Rails アプリケーションを作成しようとしています。Rails アプリを作成しましたが、問題なく動作します。しかし、mySQL データベースに接続しようとすると、奇妙なエラーが発生します。これは、何時間にもわたってグーグルで探し回った後も解決できませんでした。Rails と Ruby に慣れていないばかげた間違いを犯しているのかもしれません。
MYSQLでアプリを作成する方法は次のとおりです
コマンドプロンプトで
rails new sample_app -d mysql
[成功]
新しいコマンド プロンプト ウィンドウを開き、
C:\sites\cd sample_app> rails -s
今、私はこのエラーを受け取ります
Could not find gem mysq12 (>=0) in any of the gem sources listed in your Gemfile
Run bundle install to install missing gems
注: Mysql を使用せずに最初の Rails アプリを作成したとき、エラーは発生しませんでした。
次に、このコマンドを実行しました
gem インストール mysql2
そしてこれを手に入れた
Temporarily enhancing PATH to include DevKit...
Building native extensions. This could take a while...
ERROR: Error installing mysql2:
ERROR: Failed to build gem native extension.
C:/RailsInstaller/Ruby1.8.7/bin/ruby.exe extconf.rb
checking for rb_thread_blocking_region()... no
checking for rb_wait_for_single_fd()... no
checking for rb_hash_dup()... no
checking for rb_intern3()... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.
次にこれを実行しました-
バンドル インストール
すべてのコマンドプロンプトウィンドウを閉じ、新しいウィンドウを開き、アプリディレクトリに移動して入力しました
レール -s
エラー:
could not find gem mysq12 (>=0) in any of the gem sources listed in your Gemfile
Run bundle install to install missing gems
役に立つと思う情報をいくつか紹介します
- Rails 3.0.9
- Ruby 1.8.7
- rake (10.1.0, 0.8.7)
- mysql (2.9.1 x86-mingw32)
- MySql 5.6 installed and running (I have created a DB and tables)
- OS: Windows 7 64bit
私の database.yaml ファイルは次のようになります。
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: sample_app_development
pool: 5
username: root
password: buiskol
host: localhost
アプリの gemfile は次のようになります。
source 'http://rubygems.org'
gem 'rails', '3.0.9'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'mysql2', '~> 2.9.1'
問題は、私の mysql2 gem が正しくインストールされていないことだと思います。どこで間違いを犯しているのかわかりません。どんな助けでも大歓迎です。