我目前正在使用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/
原文地址:https://codeday.me/bug/20190702/1356856.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。