mysql - Activerecord 错误:Mysql2::Error: MySQL 服务器已消失

标签 mysql ruby activerecord mysql2 puma

我研究过以前的问题,这些问题看起来与我的问题相似,但似乎没有什么相关的。 执行以下查询后:

Runner::Models::Job.where(:id => job_id)

我遇到异常,它偶尔会发生: Mysql2::错误:MySQL 服务器已消失:SELECT jobs.* FROM jobs WHERE jobs.id = 7507 限制 1

我使用 puma,在 config.ru 中我使用:

use ActiveRecord::ConnectionAdapters::ConnectionManagement

问题是这个错误总是发生在同一个地方,我不知道为什么会发生,我检查了内存、CPU 等......,一切看起来都很正常。 也许有人会有想法。 谢谢!

最佳答案

像这样编写你的 Resque 任务:

class MyTask
  def self.perform
    ActiveRecord::Base.verify_active_connections!
    # rest of your code
  end
end

在此处查看更多详细信息:https://github.com/resque/resque/wiki/FAQ#how-do-you-work-around-the-mysql-server-has-gone-away-error-

关于mysql - Activerecord 错误:Mysql2::Error: MySQL 服务器已消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31959540/

相关文章:

ruby-on-rails - 在 ruby​​ on rails 中查找关联中的所有 nil

php - Codeigniter 2.1 - 将 HTML 页面插入数据库

ruby - Ruby 中赋值时的 bool 运算

ruby - 如何循环访问链接并使用 Watir 单击每个链接

ruby - Homebrew、Jekyll、RVM 和 usr/local

mysql - Rails 和预先存在的 MySQL 数据库 : Is there an easy way to integrate database structure into Active Record?

ruby-on-rails - rails : How do I autocomplete search for Name but save ID?

mysql - Mysql中如何删除某个代码范围

PHP获取数组mysql

php - 按行号从 MySQL 数据库中删除特定行