我正在尝试让我的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:
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:在require' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/bundler-1.3.4/ lib/bundler/runtime.rb:72:in
块中(2级)in require' 来自C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/bundler-1.3.4/ lib / bundler / runtime.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
块中的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:在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
块中' 来自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:require' from script/rails:6:in
'
我能够使用默认的SQLite运行rails服务器但是在我的生活中我无法使用MySQL。如果有人能帮我解决这个问题会有很大的帮助!
由于
答案 0 :(得分:3)
<强>更新强>
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
答案 1 :(得分:1)
Install Mysql如果您没有安装它。
下载MySQL-connector(zip文件) - 下载noinstall版本(不适用于安装)。您应该将其提取到c:\mysql-connector-c-your-version-download
将libmysql.dll
从c:\mysql-connector-c-your-version-download
复制到C:\RailsInstaller\Ruby1.9.3\bin
安装MySQL gem
gem install mysql --platform=ruby -- --with-mysql-dir=C:/mysql-connector-c-your-version-download