gpt4 book ai didi

mysql - Node : MySQL sometimes raises ETIMEDOUT error

转载 作者:可可西里 更新时间:2023-11-01 07:07:58 24 4
gpt4 key购买 nike

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

但是经常服务器报这个错,我无法和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 }

有人有办法解决这个问题吗?

谢谢

最佳答案

从你的问题来看,我假设你可以完美地使用你的数据库,但这个错误经常发生在连接建立的给定时间之后......

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

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: 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() {});

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


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

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-change-the-mysql-timeout-on-a-server/

关于mysql - Node : MySQL sometimes raises ETIMEDOUT error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34003770/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com