簡體   English   中英

無法使Rails Server與MySQL一起使用

[英]Can't get Rails Server to work with MySQL

我正在嘗試讓我的Rails應用程序與MySQL一起使用,而不是默認的SQLite。 我創建了一個新項目,該項目強制使用似乎正常運行的MySQL。

它在Gem文件中添加了gem條目,如下所示:

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 gem:

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

但是當我嘗試運行rails服務器時,我得到了:

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 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 :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來自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從C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/bundler-1.3.4/ lib / bundler / runtime.rb中的(在2個級別中)require:rb:70: each' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/bundler-1.3.4/ lib/bundler/runtime.rb:70:in C中的require塊中: RailsInstaller / Ruby1.9.3 / lib / ruby​​ / gems / 1.9.1 / gems / bundler-1.3.4 / lib / bu ndler / 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來自C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/bundler-1.3.4/ lib / bundler.rb:132:in require'from require' from C:/Users/n00151956/Desktop/RubyProjects/Demo/config/application.rb: 7:in來自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 in'來自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 script / rails:6: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 require' from script/rails:6:in

我能夠使用默認的SQLite運行Rails服務器,但是我一生都無法在MySQL中使用它。 如果有人可以幫助我,那將是很大的幫助!

謝謝

  1. 從-mysql -connector下載libmysql.dll文件,並將其放在C:\\ RailsInstaller \\ Ruby1.9.3 \\ bin應該在此處圖片
  2. 以管理員身份打開命令提示符,並通過以下方式啟動mysql服務器:C:\\ Program Files \\ MySQL \\ MySQL Server 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

如果沒有安裝Mysql,請安裝它。

  1. 下載MySQL連接器 (zip文件)-下載noinstall版本(不適用於安裝)。 您應該將其解壓縮到c:\\mysql-connector-c-your-version-download

  2. libmysql.dllc:\\mysql-connector-c-your-version-download C:\\RailsInstaller\\Ruby1.9.3\\binC:\\RailsInstaller\\Ruby1.9.3\\bin

  3. 安裝MySQL gem

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM