2013-10-02 47 views
0

我試圖在Windows中使用MySQL作爲數據庫創建Rails應用程序。我創建了一個rails應用程序,它運行得很好。但是,當我嘗試連接到mySQL數據庫時,我收到了奇怪的錯誤,在谷歌搜索和搜索幾個小時後我無法解決這些錯誤。也許我正在執行一個愚蠢的錯誤,對Rails和Ruby來說是新的。從Windows的Rails應用程序無法連接到MySql

這裏是我與MySQL

  1. 創建的應用程序在命令提示符下是如何進行的

    軌新sample_app -d mysql的

[成功]

  1. 打開一個新的c ommand提示窗口,

    C:\網站\ CD sample_app>軌-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應用程序沒有使用Mysql。

  1. 接下來,我跑這個命令

    創業板安裝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. 
  1. 接下來,我跑這一個 -

    捆綁安裝

  2. 關閉了所有命令提示符窗口,開闢一個新的,搬到了我的應用程序目錄,鍵入

    軌-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寶石沒有正確安裝。我不確定我在犯什麼錯誤。任何幫助都感激不盡。

回答

1

爲什麼使用gem'mysql2','〜> 2.9.1'而不是gem「mysql2」,「〜> 0.3.13」?根據this,沒有任何2.9.1版本,也許你的意思是0.2.9?否則,您正在安裝該版本的錯誤版本,或者安裝了正確版本的錯誤版本。

你應該使用:

gem "mysql", "~> 2.9.1" 

gem "mysql2", "~> 0.3.13" 

在寶石文件。由於沒有mysql2的版本2.9.1,請糾正錯字並重試

+1

謝謝男人,我現在已經在你的幫助下解決了這個問題。 –

相關問題