我试图让我的 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
'来自 C:/RailsInstaller/ Ruby1.9.3/lib/ruby/gems/1.9.1/gems/mysql2-0.3.11-x86-mingw32/lib/mysql2.rb:9:inrequire' 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:inrequire' 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' 来自 C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9 .1/gems/bundler-1.3.4/lib/bundler/runtime.rb:70:ineach' 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' 来自 C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/bundler- 1.3.4/lib/bundler/runtime.rb:59:ineach' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/bundler-1.3.4/ lib/bundler/runtime.rb:59:in
require' 来自 C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/bundler-1.3.4/lib/bundler.rb :132:在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:inrequire' 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 '来自 C:/RailsInstaller/ Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.1 3/lib/rails/commands.rb:50:intap' 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:inrequire' from script/rails:6:in
'
我能够让 Rails 服务器使用默认 SQLite 运行,但对于我来说,我无法让它与 MySQL 一起使用。如果有人可以帮助我解决这个问题,那将是很大的帮助!
谢谢