NodeJS:MySQL有时会引发ETIMEDOUT错误 [英] NodeJS: MySQL sometimes raises ETIMEDOUT error

查看:577
本文介绍了NodeJS:MySQL有时会引发ETIMEDOUT错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用NodeJS开发应用程序.

I'm currently developing an application using NodeJS.

但是,服务器经常会抛出此错误,并且我无法与mysql交互.

However, often the server throws this error, and I can't interact with mysql.

 [Error: read ETIMEDOUT]
  code: 'ETIMEDOUT',
  errno: 'ETIMEDOUT',
  syscall: 'read',
  fatal: true }
{ [Error: Cannot enqueue Query after fatal error.] code: 'PROTOCOL_ENQUEUE_AFTER_FATAL_ERROR', fatal: false }

有人可以解决此问题吗?

Does someone have a solution to fix that?

谢谢

推荐答案

从您的问题开始,我假设您可以完美地使用数据库,但是在建立连接的给定时间后通常会发生此错误...

From your question, I assume that you can work with your database perfectly but this error happens often after a given time of that connection being up...

假设您正在使用node-mysql
来源: https://github.com/felixge/node-mysql#error-handling
您的错误会终止您与数据库的连接:

Supposing you are using node-mysql
Source : https://github.com/felixge/node-mysql#error-handling
Your error terminates your connection to the database :

err.fatal:布尔值,指示此错误是否是连接对象的终端.
如果错误不是来自MySQL协议操作,则不会定义此属性.

err.fatal: Boolean, indicating if this error is terminal to the connection object.
If the error is not from a MySQL protocol operation, this property will not be defined.

注意:错误"事件在节点中是特殊的.如果它们发生时没有 附加的侦听器,将打印堆栈跟踪,并且您的过程是 被杀死.

Note: 'error' events are special in node. If they occur without an attached listener, a stack trace is printed and your process is killed.

tl; dr::该模块不希望您处理静默故障.你 应该始终为您的方法调用提供回调.如果你想 忽略此建议并抑制未处理的错误,您可以执行以下操作:

tl;dr: This module does not want you to deal with silent failures. You should always provide callbacks to your method calls. If you want to ignore this advice and suppress unhandled errors, you can do this:

    // I am Chuck Norris:
connection.on('error', function() {});

由此您可以检查连接状态,并在需要时执行重新连接.

From this you could check connection status and perform a reconnect if needed.

您也可以尝试手动连接到mysql服务并更改请求超时:

You could also try to connect manually to your mysql service and change request timeout :

wait_timeout" : the amount of seconds during inactivity that MySQL will wait before it will close a connection on a non-interactive connection in seconds.

http://www.serveridol.com/2012/04/13/mysql-interactive_timeout-vs-wait_timeout/
https://support. rackspace.com/how-to/how-to-to-change-the-mysql-timeout-on-a-server/

http://www.serveridol.com/2012/04/13/mysql-interactive_timeout-vs-wait_timeout/
https://support.rackspace.com/how-to/how-to-change-the-mysql-timeout-on-a-server/

这篇关于NodeJS:MySQL有时会引发ETIMEDOUT错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆