【发布时间】:2026-01-30 03:15:01
【问题描述】:
我正在尝试让我的 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:inblock (2 级别) 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:inblock 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:inrequire' 来自 C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/bundler-1.3.4/ lib/bundle.rb:132:inrequire' 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:inblock 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' 来自脚本/rails:6:inrequire' from script/rails:6:in'
我能够让 Rails 服务器使用默认 SQLite 运行,但在我的一生中,我无法让它与 MySQL 一起使用。如果有人可以帮助我解决这个问题,那将是很大的帮助!
谢谢
【问题讨论】:
-
尝试运行
bundle exec rails server -
返回相同的东西。
-
你下载了MySQL Connector/C,然后将
libmysql.dll从它复制到你的railsinstaller安装吗? -
不,我该怎么做?
标签: ruby-on-rails