简体   繁体   English

节点mysql连接超时

[英]node-mysql connectTimeout

I'm using Nodejs to write a socket server for my app (using Corona SDK), and so far so good, and I'm using node-mysql ( page for node-mysql ), and that works too, but... if nothing happens and nothing uses the connection to the db, after 2 minutes (which is the default timeout) the connection closes, while I need it to remain always open as long as the scrip process is still running, can I simply set the timeout attribute of the connection to 0, and that will keep it always open, or do I need to set it for a really long time, like 24 hours (in millisecond) in order to keep it up at all times (I'm putting 24 hours since our server restarts once a day anyway). 我正在使用Node.js为我的应用程序编写套接字服务器(使用Corona SDK),到目前为止,效果很好,并且我正在使用node-mysql(node-mysql的页面 ),它也可以工作,但是...如果什么都没发生并且什么都没有使用到数据库的连接,则在2分钟(这是默认超时)之后,该连接将关闭,而只要scrip进程仍在运行,我需要使其始终保持打开状态,我是否可以简单地设置超时连接的属性设置为0,这将使其始终保持打开状态,还是我需要将其设置很长时间,例如24小时(以毫秒为单位),以便始终保持连接状态(我将24距离我们的服务器每天都要重启一次)。

Thanks! 谢谢!

Well, it would seem the problem was the mysql server wait_timout, which was set to 300 seconds (5 minutes), and it was what disconnected my script. 好吧,看来问题出在mysql服务器wait_timout,它设置为300秒(5分钟),这是断开我脚本的原因。 seeing as I don't really want to change that variable since not only my script uses that DB, for the time being I'm simply executing a light query with a setInterval every 4 minutes, hoping this will keep my connection alive. 看到我真的不想更改该变量,因为不仅我的脚本使用了该数据库,目前我只是每隔4分钟执行一次带有setInterval的轻查询,希望这可以使我的连接保持活动状态。

If you want to keep your MySQL server always running, you have to set the connectTimeout option to 0 . 如果要保持MySQL服务器始终运行,则必须将connectTimeout选项设置为0 See the the commit "Default connectTimeout to 2 minutes" . 参见提交“ Default connectTimeout to 2 minutes” 0 was the default option before. 0是以前的默认选项。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM