python - 与我的 MYSQL connect_timeout 单位混淆

标签 python mysql flask

我有一些代码来支持 alexa 前端。
它在 Rpi 上运行,它是 python 查询 mysql 数据库,flask-ask 等。

它一整天都完美运行,第二天早上我收到错误 2006(mysql 已消失)错误,必须重新启动 python 脚本。

我检查了我的配置和 connect_timeout = 10。

我假设这是几个小时,但似乎被定义为秒....所以我不明白我的代码是如何整天工作的,只有在晚上 sleep 后才会失败。我当然不会每 10 秒运行一次查询。

我找到了 ping 命令并想尝试它来重新建立连接,但是如果每次测试之间必须上床 sleep ,测试会有点痛苦,所以我真的想将超时设置为 10 秒这样我就可以随意重现错误并测试 ping。

有什么线索可以让它在几秒后超时吗?

最佳答案

mysql中有很多不同的超时参数,例如:

The number of seconds that the mysqld server waits for a connect packet before responding with Bad handshake.

The execution timeout for SELECT statements, in milliseconds. If the value is 0, timeouts are not enabled.

The number of seconds the server waits for activity on an interactive connection before closing it.

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/

相关文章:

python - 在 Snort 警报上执行脚本

php - MYSQL优化主键查询变化

python - 如何使用 WTForms 省略 <input> 元素上的结束斜杠?

python - MongoKit vs MongoEngine vs Flask-MongoAlchemy for Flask

python - Flask-WTF CSRF token 丢失

python - 在 pytest 中使用命令行选项进行非 python 测试

python itertools : Using cycle with islice

java - 当语法正确时,LIKE 在 MYSQL 中不起作用

mysql - 我的 SQL BLOB (LONGBLOB) 类型损坏了我的数据

Python api删除--elasticsearch