无法让 Rails Server 与 MySQL 一起工作 [英] Can't get Rails Server to work with MySQL
问题描述
我正在尝试让我的 Rails 应用程序与 MySQL 一起工作,而不是默认的 SQLite.我创建了一个强制使用 MySQL 的新项目,该项目似乎可以正常工作.
I'm trying to get my Rails application to work with MySQL and not default SQLite. I've created a new project that forces the use MySQL which seemed to work correctly.
它在 Gem 文件中添加了 gem 条目,如下所示:
It added gem entry in the Gem file as so:
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:
And when I run the bundle command it shows that its using mysql gem:
Using mysql2 <0.3.11>
我也将 database.yml 文件配置如下:
I've also configure the database.yml file as so:
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 服务器时,我得到了这个:
But when I try to run the rails server I get this:
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: 指定的模块可以找不到.——C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/mysql2-0.3.11-x86-mingw32/lib/mysql2/1.9/mysql2.so (LoadError)来自 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:in require'来自 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'来自 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:in each'来自 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:in each'来自 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:in require'来自 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.13/lib/rails/commands.rb:53:in require'来自 C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.13/lib/rails/commands.rb:53:in
block in '来自 C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.13/lib/rails/commands.rb:50:in tap'来自 C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.13/lib/rails/commands.rb:50:in
'来自 script/rails:6:in require'来自 script/rails:6:in
'
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: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
' from 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' from 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' from 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' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/bundler-1.3.4/ lib/bundler.rb:132:inrequire' 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: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 ' from 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
' from script/rails:6:inrequire' from script/rails:6:in
'
我能够使用默认的 SQLite 运行 rails 服务器,但是在我的一生中,我无法让它与 MySQL 一起工作.如果有人能帮我解决这个问题,那将是非常有帮助的!
I was able to get the rails server running with default SQLite but for the life of me I can't get it working with MySQL. If anyone can help me out with this that would be great help!
谢谢
推荐答案
- 从-mysql-connector 并把它放在 C:\RailsInstaller\Ruby1.9.3\bin 应该在这里 图片
- 以管理员身份打开命令提示符并按以下方式启动 mysql 服务器:C:\Program Files\MySQL\MySQL Server 5.0\bin\mysql
- Download libmysql.dll file from - mysql-connector and put it in C:\RailsInstaller\Ruby1.9.3\bin should be here Image
- open command prompt as administrator and start the mysql server the following way: 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
这篇关于无法让 Rails Server 与 MySQL 一起工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!