简体   繁体   中英

Delayed Job - rake jobs:clear causes "Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

My database.yml file:

production:
  adapter: mysql2
  database: app_production
  host: 127.0.0.1
  username: root
  password: 12345678
  port: 3306
  pool: 15
  timeout: 5000
  socket: /var/run/mysqld/mysqld.sock

(Removing the socket line does not help)

Path according to my.cnf:

/var/run/mysqld/mysqld.sock

Mysql is running because my app is up, but when I run:

 rake jobs:clear

from the console, I get:

rake aborted!
Mysql2::Error: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
/home/deploy/dispatch/shared/bundle/ruby/2.2.0/gems/mysql2-0.3.18/lib/mysql2/client.rb:70:in `connect'
/home/deploy/dispatch/shared/bundle/ruby/2.2.0/gems/mysql2-0.3.18/lib/mysql2/client.rb:70:in `initialize'
/home/deploy/dispatch/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/mysql2_adapter.rb:18:in `new'
/home/deploy/dispatch/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/mysql2_adapter.rb:18:in `mysql2_connection'
/home/deploy/dispatch/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:438:in `new_connection'
/home/deploy/dispatch/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:448:in `checkout_new_connection'
/home/deploy/dispatch/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:422:in `acquire_connection'
/home/deploy/dispatch/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:349:in `block in checkout'
/home/deploy/dispatch/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:348:in `checkout'
/home/deploy/dispatch/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:263:in `block in connection'
/home/deploy/dispatch/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:262:in `connection'
/home/deploy/dispatch/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:567:in `retrieve_connection'
/home/deploy/dispatch/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.1/lib/active_record/connection_handling.rb:113:in `retrieve_connection'
/home/deploy/dispatch/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.1/lib/active_record/connection_handling.rb:87:in `connection'
/home/deploy/dispatch/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.1/lib/active_record/relation.rb:477:in `delete_all'
/home/deploy/dispatch/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.1/lib/active_record/querying.rb:8:in `delete_all'
/home/deploy/dispatch/shared/bundle/ruby/2.2.0/gems/delayed_job-4.0.6/lib/delayed/tasks.rb:4:in `block (2 levels) in <top (required)>'
Tasks: TOP => jobs:clear

Delayed job will take the database configuration associated with the rails environment your application is running in.

If you just run rake jobs:clear , it'll run by default in development mode and will try to connect to your development database. If you want delayed_job to connect to your production database, you need to set the environment accordingly, ie production:

RAILS_ENV=production rake jobs:clear

By the way, keep the socket line in your database.yml , otherwise it'll default to /tmp/mysql.sock .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM