Rails:无法在' localhost'上连接到MySQL服务器(10061)(Mysql ::错误)

时间:2012-11-16 10:47:11

标签: ruby-on-rails-3

我有一个奇怪的问题。当我尝试ro rails s时,它会说:

C:/Ruby/ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/conne
ction_adapters/mysql_adapter.rb:411:in `real_connect': Can't connect to MySQL se
rver on '127.0.0.0' (10060) (Mysql::Error)
        from C:/Ruby/ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active
_record/connection_adapters/mysql_adapter.rb:411:in `connect'
        from C:/Ruby/ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active
_record/connection_adapters/mysql_adapter.rb:131:in `initialize'
        from C:/Ruby/ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active
_record/connection_adapters/mysql_adapter.rb:38:in `new'
        from C:/Ruby/ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active
_record/connection_adapters/mysql_adapter.rb:38:in `mysql_connection'
        from C:/Ruby/ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active
_record/connection_adapters/abstract/connection_pool.rb:309:in `new_connection'
        from C:/Ruby/ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active
_record/connection_adapters/abstract/connection_pool.rb:319:in `checkout_new_con
nection'
        from C:/Ruby/ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active
_record/connection_adapters/abstract/connection_pool.rb:241:in `block (2 levels)
 in checkout'
        from C:/Ruby/ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active
_record/connection_adapters/abstract/connection_pool.rb:236:in `loop'
        from C:/Ruby/ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active
_record/connection_adapters/abstract/connection_pool.rb:236:in `block in checkou
t'
        from C:/Ruby/ruby/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
        from C:/Ruby/ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active
_record/connection_adapters/abstract/connection_pool.rb:233:in `checkout'
        from C:/Ruby/ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active
_record/connection_adapters/abstract/connection_pool.rb:96:in `block in connecti
on'
        from C:/Ruby/ruby/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
        from C:/Ruby/ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active
_record/connection_adapters/abstract/connection_pool.rb:95:in `connection'
        from C:/Ruby/ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active
_record/connection_adapters/abstract/connection_pool.rb:404:in `retrieve_connect
ion'
        from C:/Ruby/ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active
_record/connection_adapters/abstract/connection_specification.rb:170:in `retriev
e_connection'
        from C:/Ruby/ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active
_record/connection_adapters/abstract/connection_specification.rb:144:in `connect
ion'
        from C:/Ruby/ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active
_record/model_schema.rb:308:in `clear_cache!'
        from C:/Ruby/ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active
_record/railtie.rb:97:in `block (2 levels) in <class:Railtie>'
        from C:/Ruby/ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.2.8/lib/activ
e_support/callbacks.rb:418:in `_run__319095901__prepare__837475246__callbacks'
        from C:/Ruby/ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.2.8/lib/activ
e_support/callbacks.rb:405:in `__run_callback'
        from C:/Ruby/ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.2.8/lib/activ
e_support/callbacks.rb:385:in `_run_prepare_callbacks'
        from C:/Ruby/ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.2.8/lib/activ
e_support/callbacks.rb:81:in `run_callbacks'
        from C:/Ruby/ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.2.8/lib/action_d
ispatch/middleware/reloader.rb:74:in `prepare!'
        from C:/Ruby/ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.2.8/lib/action_d
ispatch/middleware/reloader.rb:48:in `prepare!'
        from C:/Ruby/ruby/lib/ruby/gems/1.9.1/gems/railties-3.2.8/lib/rails/appl
ication/finisher.rb:47:in `block in <module:Finisher>'
        from C:/Ruby/ruby/lib/ruby/gems/1.9.1/gems/railties-3.2.8/lib/rails/init
ializable.rb:30:in `instance_exec'
        from C:/Ruby/ruby/lib/ruby/gems/1.9.1/gems/railties-3.2.8/lib/rails/init
ializable.rb:30:in `run'
        from C:/Ruby/ruby/lib/ruby/gems/1.9.1/gems/railties-3.2.8/lib/rails/init
ializable.rb:55:in `block in run_initializers'
        from C:/Ruby/ruby/lib/ruby/gems/1.9.1/gems/railties-3.2.8/lib/rails/init
ializable.rb:54:in `each'
        from C:/Ruby/ruby/lib/ruby/gems/1.9.1/gems/railties-3.2.8/lib/rails/init
ializable.rb:54:in `run_initializers'
        from C:/Ruby/ruby/lib/ruby/gems/1.9.1/gems/railties-3.2.8/lib/rails/appl
ication.rb:136:in `initialize!'
        from C:/Ruby/ruby/lib/ruby/gems/1.9.1/gems/railties-3.2.8/lib/rails/rail
tie/configurable.rb:30:in `method_missing'
        from C:/Ruby/acturevue/config/environment.rb:5:in `<top (required)>'
        from C:/Ruby/ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.2.8/lib/activ
e_support/dependencies.rb:251:in `require'
        from C:/Ruby/ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.2.8/lib/activ
e_support/dependencies.rb:251:in `block in require'
        from C:/Ruby/ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.2.8/lib/activ
e_support/dependencies.rb:236:in `load_dependency'
        from C:/Ruby/ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.2.8/lib/activ
e_support/dependencies.rb:251:in `require'
        from C:/Ruby/acturevue/config.ru:4:in `block in <main>'
        from C:/Ruby/ruby/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/builder.r
b:51:in `instance_eval'
        from C:/Ruby/ruby/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/builder.r
b:51:in `initialize'
        from C:/Ruby/acturevue/config.ru:1:in `new'
        from C:/Ruby/acturevue/config.ru:1:in `<main>'
        from C:/Ruby/ruby/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/builder.r
b:40:in `eval'
        from C:/Ruby/ruby/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/builder.r
b:40:in `parse_file'
        from C:/Ruby/ruby/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/server.rb
:200:in `app'
        from C:/Ruby/ruby/lib/ruby/gems/1.9.1/gems/railties-3.2.8/lib/rails/comm
ands/server.rb:46:in `app'
        from C:/Ruby/ruby/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/server.rb
:301:in `wrapped_app'
        from C:/Ruby/ruby/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/server.rb
:252:in `start'
        from C:/Ruby/ruby/lib/ruby/gems/1.9.1/gems/railties-3.2.8/lib/rails/comm
ands/server.rb:70:in `start'
        from C:/Ruby/ruby/lib/ruby/gems/1.9.1/gems/railties-3.2.8/lib/rails/comm
ands.rb:55:in `block in <top (required)>'
        from C:/Ruby/ruby/lib/ruby/gems/1.9.1/gems/railties-3.2.8/lib/rails/comm
ands.rb:50:in `tap'
        from C:/Ruby/ruby/lib/ruby/gems/1.9.1/gems/railties-3.2.8/lib/rails/comm
ands.rb:50:in `<top (required)>'
        from script/rails:6:in `require'

我无法理解的是,昨天一切运转良好!今天早上,Windows更新了,所以也许有一个链接,没有?

此外,我无法访问localhost:3000,但我可以通过以下方式连接到PhpMyAdmin的登录页面(它在写入我的登录名/密码后拒绝连接):localhost:81

我在撰写这篇文章之前找到了一些解决方案,但没有人为我工作!

提前致谢。

更新

这是我的db.yml:

# And be sure to use new-style password hashing:
#   http://dev.mysql.com/doc/refman/5.0/en/old-client.html
development:
  adapter: mysql
  encoding: utf8
  reconnect: false
  database: acturevue_development
  pool: 5
  username: root
  password: password
  host: localhost

更新 Gemfile以查看gem是否可能成为问题:

    source 'http://rubygems.org'

gem 'rails', '3.2.8'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'

gem 'mysql'



# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails',   '~> 3.2.3'
  gem 'coffee-rails', '~> 3.2.1'

  # See https://github.com/sstephenson/execjs#readme for more supported runtimes
  # gem 'therubyracer', :platforms => :ruby

  gem 'uglifier', '>= 1.0.3'
end

gem 'jquery-rails'

# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'

# To use Jbuilder templates for JSON
# gem 'jbuilder'

# Use unicorn as the app server
# gem 'unicorn'

# Deploy with Capistrano
# gem 'capistrano'

# To use debugger
# gem 'debugger'


gem 'geocoder'
gem 'gmaps4rails'
gem "bootstrap-sass", ">= 2.1.0.0"

gem "rolify", ">= 3.2.0"
gem "simple_form", ">= 2.0.3"
gem "paperclip", "~> 3.0"

2 个答案:

答案 0 :(得分:3)

您必须为mysql指定套接字

development:
 adapter: mysql
 encoding: utf8
 reconnect: false
 database: acturevue_development
 pool: 5
 username: root
 password: password
 host: localhost
 socket: /opt/lampp/var/mysql/mysql.sock //this path must point to your mysql socket

P.S。你需要在Linux和Windows下指定这个选项,在Mac OS下并不完全确定。

答案 1 :(得分:0)

请尝试以下操作。

在宝石文件中

  

gem'mysql','2.8.1'

在database.yml

发展:

adapter: mysql
 encoding: utf8
  reconnect: false
  database: acturevue_development
  pool: 5
  username: root
 password: password
  host: 127.0.0.0

希望它对您有用:)