2013-05-28 97 views
2

我想讓我的Rails應用程序與MySQL一起工作,而不是默認的SQLite。我創建了一個新的項目,強制使用似乎正常工作的MySQL。無法讓Rails服務器與MySQL一起工作

它添加在寶石文件寶石條目這樣:

source 'https://rubygems.org' 

    gem 'rails', '3.2.13' 

    # Bundle edge Rails instead: 
    # gem 'rails', :git => 'git://github.com/rails/rails.git' 

    gem 'mysql2' 

當我運行bundle命令它表明其用mysql寶石:

Using mysql2 <0.3.11> 

我也配置database.yml文件,像這樣:

development: 
adapter: mysql2 
encoding: utf8 
reconnect: false 
database: dbname 
pool: 5 
username: uname 
password: pass 
host: hostname 

test: 
development: 
adapter: mysql2 
encoding: utf8 
reconnect: false 
database: dbname 
pool: 5 
username: uname 
password: pass 
host: hostname 

production: 
development: 
adapter: mysql2 
encoding: utf8 
reconnect: false 
database: dbname 
pool: 5 
username: uname 
password: pass 
host: hostname 

但是當我嘗試運行軌道服務器我得到這個:

C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/mysql2-0.3.11-x86-mingw32/l ib/mysql2/mysql2.rb:2:in require': 126: The specified module could not be found . - C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/mysql2-0.3.11-x86-min gw32/lib/mysql2/1.9/mysql2.so (LoadError) from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/mysql2-0.3.11- x86-mingw32/lib/mysql2/mysql2.rb:2:in ' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/mysql2-0.3.11- x86-mingw32/lib/mysql2.rb:9:in require' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/mysql2-0.3.11- x86-mingw32/lib/mysql2.rb:9:in ' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/bundler-1.3.4/ lib/bundler/runtime.rb:72:in require' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/bundler-1.3.4/ lib/bundler/runtime.rb:72:in block (2 levels) in require' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/bundler-1.3.4/ lib/bundler/runtime.rb:70:in each' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/bundler-1.3.4/ lib/bundler/runtime.rb:70:in block in require' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/bundler-1.3.4/ lib/bundler/runtime.rb:59:in each' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/bundler-1.3.4/ lib/bundler/runtime.rb:59:in require' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/bundler-1.3.4/ lib/bundler.rb:132:in require' from C:/Users/n00151956/Desktop/RubyProjects/Demo/config/application.rb: 7:in ' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.1 3/lib/rails/commands.rb:53:in require' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.1 3/lib/rails/commands.rb:53:in block in ' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.1 3/lib/rails/commands.rb:50:in tap' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.1 3/lib/rails/commands.rb:50:in ' from script/rails:6:in require' from script/rails:6:in '

我能得到默認的SQLite運行軌道服務器,但對我的生活,我不能讓它使用MySQL。如果有人能幫助我,這將是很大的幫助!

由於從

+0

嘗試運行'捆綁高管軌server' – tolgap

+0

它返回同樣的事情。 – Nick

+0

你有沒有下載** MySQL Connector/C **,然後將'libmysql.dll'從它拷貝到你的railsinstaller安裝中? –

回答

3
  1. 下載libmysql.dll的文件 - mysql-connector,並把它放在C:\ RailsInstaller \ Ruby1.9.3 \ BIN應該在這裏Image
  2. 打開命令提示符以管理員身份並啓動MySQL服務器方式如下:C:\ Program Files文件\的MySQL \ MySQL服務器5.0 \ BIN \ mysql的

更新

development: 
    adapter: mysql2 
    database: proj_development 
    username: root 
    password: pass 
    host: 127.0.0.1 
    socket: /tmp/mysql.sock 

test: 
    adapter: mysql2 
    database: proj_test 
    username: root 
    password: pass 
    host: 127.0.0.1 
    socket: /tmp/mysql.sock 

production: 
    adapter: mysql2 
    database: proj_production 
    username: root 
    password: pass 
    host: 127.0.0.1 
    socket: /tmp/mysql.sock 
+0

當我運行第二個命令我得到這個錯誤:ERROR 2003(HY000):無法連接到MySQL服務器上的「localhost」(10061) – Nick

+0

查看更新和更改綁定地址爲127.0.0.1 – David

+0

如果什麼MySQL是沒有在本地主機上運行?我有它運行在不同的服務器上。 – Nick

1

Install Mysql如果你沒有安裝它。

  1. 下載MySQL-connector(zip文件) - 下載noinstall版本(不適用於安裝)。你應該從c:\mysql-connector-c-your-version-download提取到c:\mysql-connector-c-your-version-download

  2. 副本libmysql.dllC:\RailsInstaller\Ruby1.9.3\bin

  3. 安裝MySQL寶石

    gem install mysql --platform=ruby -- --with-mysql-dir=C:/mysql-connector-c-your-version-download

相關問題