检查 MySQL 服务器何时准备好运行查询而不中断查询 [英] Checking when a MySQL server is ready to run queries without interrupting them

查看:69
本文介绍了检查 MySQL 服务器何时准备好运行查询而不中断查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Percona Docker 镜像,纯粹是为了本地测试(5.6,因为这是我需要测试的对象).

I'm using the Percona Docker image, purely for local testing purposes (5.6 because that's what I need to test against).

我想在服务器准备好时运行一个初始化脚本.到目前为止,我已经尝试了其他类似问题中提到的两件事:mysqladmin ping --silentmysqladmin -uroot status.

I want to run an initialization script when the server is ready. I've tried two things so far that have been mentioned in other similar questions: mysqladmin ping --silent, and mysqladmin -uroot status.

但是,在这两种情况下,当我在返回 0 后运行初始化脚本时,脚本会在一两秒内中断(ERROR 1317 (70100) at line ___:查询执行被中断).大部分脚本运行,但最后几个查询没有运行.

However, in both these cases, when I run the initialization script once they return 0, the script gets interrupted within a second or two (ERROR 1317 (70100) at line ___: Query execution was interrupted). Most of the script runs, but the last few queries don't make it.

如果我等待这些命令返回 0,然后 然后 再睡 5 秒钟左右,我就不会被打扰.为什么会有这种行为差异?以及如何在运行 init 脚本之前对其进行测试,以便我不必在代码中保留丑陋的 sleep 5?

If I wait for these commands to return 0, and then sleep for another 5 seconds or so, I don't get interrupted. Why is there this difference in behavior? And how can I test for it before I run the init script so that I don't have to keep an ugly sleep 5 in my code?

推荐答案

结果是官方的 Percona docker 镜像在 MySQL 完全启动之前启动并关闭了几次,导致中断.

Turns out the official Percona docker image starts and shuts MySQL down a couple times before it's fully up, causing the interruptions.

这可以通过 docker run percona:5.6 验证.

这个问题 了解更多详情.

这篇关于检查 MySQL 服务器何时准备好运行查询而不中断查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆