gpt4 book ai didi

mysql - 将 MySQL 连接到 Ruby on Rails - ActiveRecord::ConnectionNotEstablished

转载 作者:行者123 更新时间:2023-11-30 23:08:43 25 4
gpt4 key购买 nike

我已经安装了带有现有数据库的 MySQL Workbench,准备就绪。我安装了 Rails 并将我的 database.yml 文件配置为读取:

development:
adapter: mysql2
encoding: utf8
database: unibands
pool: 5
username: root
password:
host: localhost

但是,当导航到 http://localhost:3000 上的任何地方时,我收到错误消息:ActiveRecord::ConnectionNotEstablished

终端中的“完整”错误如下:

Started GET "/pins/index" for 127.0.0.1 at 2013-12-20 19:47:12 +0000

ActiveRecord::ConnectionNotEstablished (ActiveRecord::ConnectionNotEstablished):
activerecord (4.0.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:546:in `retrieve_connection'
activerecord (4.0.2) lib/active_record/connection_handling.rb:79:in `retrieve_connection'
activerecord (4.0.2) lib/active_record/connection_handling.rb:53:in `connection'
activerecord (4.0.2) lib/active_record/query_cache.rb:51:in `restore_query_cache_settings'
activerecord (4.0.2) lib/active_record/query_cache.rb:43:in `rescue in call'
activerecord (4.0.2) lib/active_record/query_cache.rb:32:in `call'
activerecord (4.0.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:626:in `call'
activerecord (4.0.2) lib/active_record/migration.rb:369:in `call'
actionpack (4.0.2) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.0.2) lib/active_support/callbacks.rb:373:in `_run__4325676049139756285__call__callbacks'
activesupport (4.0.2) lib/active_support/callbacks.rb:80:in `run_callbacks'
actionpack (4.0.2) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.0.2) lib/action_dispatch/middleware/reloader.rb:64:in `call'
actionpack (4.0.2) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
actionpack (4.0.2) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
actionpack (4.0.2) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.0.2) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.0.2) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.0.2) lib/active_support/tagged_logging.rb:67:in `block in tagged'
activesupport (4.0.2) lib/active_support/tagged_logging.rb:25:in `tagged'
activesupport (4.0.2) lib/active_support/tagged_logging.rb:67:in `tagged'
railties (4.0.2) lib/rails/rack/logger.rb:20:in `call'
actionpack (4.0.2) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
rack (1.5.2) lib/rack/runtime.rb:17:in `call'
activesupport (4.0.2) lib/active_support/cache/strategy/local_cache.rb:83:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
actionpack (4.0.2) lib/action_dispatch/middleware/static.rb:64:in `call'
rack (1.5.2) lib/rack/sendfile.rb:112:in `call'
railties (4.0.2) lib/rails/engine.rb:511:in `call'
railties (4.0.2) lib/rails/application.rb:97:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
rack (1.5.2) lib/rack/content_length.rb:14:in `call'
rack (1.5.2) lib/rack/handler/webrick.rb:60:in `service'
/usr/local/rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
/usr/local/rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
/usr/local/rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'


Rendered /usr/local/rvm/gems/ruby-1.9.3-p392/gems/actionpack-4.0.2/lib/action_dispatch/middleware/templates/rescues/_source.erb (0.5ms)
Rendered /usr/local/rvm/gems/ruby-1.9.3-p392/gems/actionpack-4.0.2/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.1ms)
Rendered /usr/local/rvm/gems/ruby-1.9.3-p392/gems/actionpack-4.0.2/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (0.9ms)
Rendered /usr/local/rvm/gems/ruby-1.9.3-p392/gems/actionpack-4.0.2/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (14.3ms)

我在装有 Rails 4.0.2 的 Mac (OS Mavericks) 上

如果我将连接更改为默认的 sqlite3,它会呈现页面。所以这绝对是我的数据库连接有问题。我是 Rails 的新手,所以这可能是一个简单的修复,但似乎对我没有任何作用。

最佳答案

如果您使用的是 MAMP,请在您的 database.yml 中添加以下内容

socket: /Applications/MAMP/tmp/mysql/mysql.sock

Mysql默认安装socket在/tmp/mysql.soc所以尝试,因为你没有运行 MAMP

socket: /tmp/mysql/mysql.sock

关于mysql - 将 MySQL 连接到 Ruby on Rails - ActiveRecord::ConnectionNotEstablished,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20711037/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com