Rails 4 Action Controller:Exception捕获了Mysql2 :: Error
尝试在localhost:3000 /上打开“Lynda.com Essential Ruby on rails 4”练习文件应用程序,这就是我得到的:
Mysql2::Error
Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
谢谢!
更新:25/01 这些是我的日志:
Started GET "/" for 127.0.0.1 at 2014-01-22 15:46:18 +0200
Mysql2::Error (Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)):
mysql2 (0.3.13) lib/mysql2/client.rb:58:in `connect'
mysql2 (0.3.13) lib/mysql2/client.rb:58:in `initialize'
activerecord (4.0.0) lib/active_record/connection_adapters/mysql2_adapter.rb:18:in `new'
activerecord (4.0.0) lib/active_record/connection_adapters/mysql2_adapter.rb:18:in `mysql2_connection'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract /connection_pool.rb:440:in `new_connection'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract /connection_pool.rb:450:in `checkout_new_connection'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract /connection_pool.rb:421:in `acquire_connection'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract /connection_pool.rb:356:in `block in checkout'
/home/ggeorgiev/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/monitor.rb:211:in ` mon_synchronize'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract /connection_pool.rb:355:in `checkout'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract /connection_pool.rb:265:in `block in connection'
/home/ggeorgiev/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:264:in `connection'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:546:in `retrieve_connection'
activerecord (4.0.0) lib/active_record/connection_handling.rb:79:in `retrieve_connection'
activerecord (4.0.0) lib/active_record/connection_handling.rb:53:in `connection'
activerecord (4.0.0) lib/active_record/migration.rb:792:in `current_version'
activerecord (4.0.0) lib/active_record/migration.rb:800:in `needs_migration?'
activerecord (4.0.0) lib/active_record/migration.rb:379:in `check_pending!'
activerecord (4.0.0) lib/active_record/migration.rb:366:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.0.0) lib/active_support/callbacks.rb:373:in `_run__4564087381787545460__call__callbacks'
activesupport (4.0.0) lib/active_support/callbacks.rb:80:in `run_callbacks'
actionpack (4.0.0) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/reloader.rb:64:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.0.0) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.0.0) lib/rails/rack/logger.rb:21:in `block in call'
activesupport (4.0.0) lib/active_support/tagged_logging.rb:67:in `block in tagged'
activesupport (4.0.0) lib/active_support/tagged_logging.rb:25:in `tagged'
activesupport (4.0.0) lib/active_support/tagged_logging.rb:67:in `tagged'
railties (4.0.0) lib/rails/rack/logger.rb:21:in `call'
actionpack (4.0.0) 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.0) 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.0) lib/action_dispatch/middleware/static.rb:64:in `call'
railties (4.0.0) lib/rails/engine.rb:511:in `call'
railties (4.0.0) 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'
/home/ggeorgiev/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/webrick/httpserver.rb:138:in `service'
/home/ggeorgiev/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/webrick/httpserver.rb:94:in `run'
/home/ggeorgiev/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread'
Rendered /home/ggeorgiev/.rvm/gems/ruby-2.0.0-p353/gems/actionpack-4.0.0/lib /action_dispatch/middleware/templates/rescues/_source.erb (0.7ms)
Rendered /home/ggeorgiev/.rvm/gems/ruby-2.0.0-p353/gems/actionpack-4.0.0/lib /action_dispatch/middleware/templates/rescues/_trace.erb (1.6ms)
Rendered /home/ggeorgiev/.rvm/gems/ruby-2.0.0-p353/gems/actionpack-4.0.0/lib /action_dispatch/middleware/templates/rescues/_request_and_response.erb (1.1ms)
Rendered /home/ggeorgiev/.rvm/gems/ruby-2.0.0-p353/gems/actionpack-4.0.0/lib /action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (16.2ms)
答案 0 :(得分:1)
服务器尚未启动。您可以从系统首选项启动它。
系统偏好 - > Mysql - >启动服务器。
否则你可以从终端开始。该命令取决于您安装MySQL的方式。先试试这个:
sudo / Library / StartupItems / MySQLCOM / MySQLCOM start
如果失败:
cd /usr/local/mysql
sudo ./bin/mysqld_safe
(Enter your password, if necessary)
(Press Control-Z)
bg
如果不起作用,请尝试以下
mysql.server start
mysqladmin variables | grep socket
对我来说,它给了,
| socket | /tmp/mysql.sock
然后在config / database.yml
中添加一行development:
adapter: mysql2
host: localhost
username: root
password: xxxx
database: xxxx
socket: /tmp/mysql.sock
希望能解决你的问题。