mysqlperconamysqladmin

Checking when a MySQL server is ready to run queries without interrupting them


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

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.

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.

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?


Solution

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

    This can be verified with a docker run percona:5.6.

    See this question for more details.