我有一些代码来支持 alexa 前端。
它在 Rpi 上运行,它是 python 查询 mysql 数据库,flask-ask 等。
它一整天都完美运行,第二天早上我收到错误 2006(mysql 已消失)错误,必须重新启动 python 脚本。
我检查了我的配置和 connect_timeout = 10。
我假设这是几个小时,但似乎被定义为秒....所以我不明白我的代码是如何整天工作的,只有在晚上 sleep 后才会失败。我当然不会每 10 秒运行一次查询。
我找到了 ping 命令并想尝试它来重新建立连接,但是如果每次测试之间必须上床 sleep ,测试会有点痛苦,所以我真的想将超时设置为 10 秒这样我就可以随意重现错误并测试 ping。
有什么线索可以让它在几秒后超时吗?
最佳答案
mysql中有很多不同的超时参数,例如:
- > connect_timeout - 默认为 10 秒
The number of seconds that the mysqld server waits for a connect packet before responding with Bad handshake.
- > max_execution_time - 默认无限制
The execution timeout for SELECT statements, in milliseconds. If the value is 0, timeouts are not enabled.
- > interactive_timeout - 默认为 8 小时
The number of seconds the server waits for activity on an interactive connection before closing it.
- > wait_timeout - 超时)- 默认为 8 小时
The number of seconds the server waits for activity on a noninteractive connection before closing it.
您需要调查哪个超时导致您的用例出现问题,并相应地进行修改。根据您对问题的描述,您解释说在您的脚本休眠时连接在一夜之间丢失,它可能是 wait_timeout
(或 interactive_timeout
,具体取决于您的连接是如何启动的).
关于python - 与我的 MYSQL connect_timeout 单位混淆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54152248/