简体   繁体   English

无法从“失去与MySQL服务器的连接”错误中解救出来

[英]Unable to rescue from “Lost connection to MySQL server” error

I have a block like so: 我有一个像这样的块:

begin
      # some SQL request
rescue Mysql::Error => e
      logputs "Mysql::Error occurred, retrying in 10s: #{e.message}"
      sleep 10
      retry
end

But when a "Lost connection to MySQL server" error occurred, this block was not able to catch it and retry (the MySQL server was restarted). 但是,当发生“与MySQL服务器的连接断开”错误时,该块无法捕获并重试(MySQL服务器已重新启动)。 Any idea how I can properly catch this exception? 知道如何正确捕获此异常吗?

Thanks! 谢谢!

From your comment it looks like what's happening is that a Mysql::Error exception is being thrown, but then caught by ActiveRecord which then throws an ActiveRecord::StatementInvalid exception (which isn't very helpful behaviour in this case!). 从您的评论看来,正在发生的事情是抛出了Mysql :: Error异常,但随后被ActiveRecord捕获,该异常随后引发了ActiveRecord :: StatementInvalid异常(在这种情况下,这不是很有用!)。

I'd say change your rescue to catch the AR::StatementInvalid exception and see what that does for you. 我想说说改变您的营救以捕获AR :: StatementInvalid异常,然后看看这对您有什么帮助。

Are you sure you are rescuing the correct type of exception? 您确定要挽救正确的异常类型吗?

Try using the following code: 尝试使用以下代码:

rescue StandardError => e
  puts e

That should output any exception that is raised and more importantly you will be able to see the specific type. 那应该输出任何引发的异常,更重要的是,您将能够看到特定的类型。 Then you can adjust your rescue statement to be more specific. 然后,您可以调整您的救援声明,使其更加具体。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法在 MySQL 数据库中创建表(错误代码:2013。在查询过程中与 MySQL 服务器的连接丢失) - Unable to Create a Table in MySQL Database (Error Code: 2013. Lost connection to MySQL server during query) 失去与MySQL服务器的连接,系统错误:111 - Lost connection to MySQL server, system error: 111 与 MySQL 服务器的连接丢失(错误:111) - Connection to MySQL server lost (error:111) 在 'localhost:3306' 与 MySQL 服务器的连接丢失,系统错误:连接不可用 - Lost connection to MySQL server at 'localhost:3306', system error: Connection not available MySQL-错误2013:查询期间与MySQL服务器的连接断开-Localhost - MySQL - Error 2013: Lost Connection to MySQL server during Query - Localhost MySQL触发器错误#2013-查询期间与MySQL服务器的连接断开 - MySQL Trigger Error #2013 - Lost connection to MySQL server during query 尝试访问服务器上的数据库时出错:断开与MySQL服务器的连接 - Error when trying to access database on server: Lost connection to MySQL server Flask返回错误:断开与MySQL服务器的连接,系统错误:60 - Flask returns error: Lost connection to MySQL server, system error: 60 pandas:“与MySQL服务器的连接丢失”“系统错误:32管道断开” - pandas: “Lost connection to MySQL server” “system error: 32 Broken pipe” 错误代码:2013。在查询过程中失去与 MySQL 服务器的连接 - Error Code: 2013. Lost connection to MySQL server during query
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM