AnyEvent::DBI 和数据库重新连接
我在单例包中使用 AnyEvent::DBI,并且当几个小时后数据库/查询等中没有活动时,我在尝试发出查询时收到此错误:
DBD::mysql::st execute failed: MySQL server has gone away at /usr/local/share/perl/5.10.1/AnyEvent/DBI.pm line 98.
一个简单的方法是:连接到 DB = =>问题查询==>关闭连接。 这是我在使用 DBI 时通常使用的方法。
我的问题是,除了创建新的 AnyEvent::DBI 实例(新)之外,我找不到使用 AnyEvent::DBI 重新连接到数据库的方法。
任何建议都会很棒!
I'm using AnyEvent::DBI in a singleton package, and when there is no activity in the database / queries etc after many hours, I get this error while trying to issue a query:
DBD::mysql::st execute failed: MySQL server has gone away at /usr/local/share/perl/5.10.1/AnyEvent/DBI.pm line 98.
A simple approach is to: connect to DB ==> Issue query ==> Close connection.
this way is what I usually use when I'm working with DBI.
The issue in my case is that I cant find a way to re-connect to the database using AnyEvent::DBI, except from creating a new AnyEvent::DBI instance (new).
Any suggestions would be great!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据 CPAN 上的 DBD::mysql 文档,您要使用:
以下是参考链接:
http://metacpan.org/pod/DBD::mysql
As per the DBD::mysql documentation on CPAN, you want to use:
Here is the link to the reference:
http://metacpan.org/pod/DBD::mysql
在 MySQL 中,有一个
wait_timeout
设置非交互式连接持续时间的变量。对于长时间运行的连接,您可以尝试将该值(默认 = 28800 )更改为更合适的值。
wait_timeout
值可以通过简单的查询进行更新并通过另一个查询进行检索
In MySQL there's a
wait_timeout
variable that sets the duration of non-interactive connections.For long-running connections you can try to alter that value ( default = 28800 ), to a more suitable one.
wait_timeout
value can be updated with a simple queryand retrieved with another one