0

I am using the following code in a Kubernetes application to probe MySQL's readiness:

handler := corev1.Handler{
        Exec: &corev1.ExecAction{
            Command: []string{"cat", fmt.Sprintf("%v/mysqld.pid", dataDir)},
        },
    }

It works better than probing TCP port 3306, which will generate a lot of error info in mysql-error.log like this: [Note] Got an error reading communication packets

My question is: Is mysqld.pid file 's existance enough to prove that MySQL server is ready to serve ?

Steve Wu
  • 143
  • 11
  • 1
    No, If (or When?) the server crashed, it is possible the `mysql.pid` file is still there, and the server is not running. what exactly are you doing that causes the error in the log? Just sending a query like `SELECT 1;` should not produce an error. – Luuk Dec 08 '21 at 11:08
  • Also your current account may have no enough permissions in the filesystem for mysqld.pid file presence detection. – Akina Dec 08 '21 at 11:15
  • see this https://bugs.mysql.com/bug.php?id=93197. Simply telnet ip 3306 would yield a [Note] record in mysql-error.log. – Steve Wu Dec 08 '21 at 11:15
  • 1
    You could also use the mysql-client, and do (something like) this: `mysql -B -utest -ptest -e "SELECT 1;"` (of course with a username/password that has, at least, SELECT privileges. – Luuk Dec 08 '21 at 11:51
  • So I have to login to be sure that MySQL is running and serving? Your solution is of course working well, but I am thinking if there is any better solution than this. Maybe a solution that doesn't require query something. – Steve Wu Dec 08 '21 at 12:44
  • Does this answer your question? [How do I know when my docker mysql container is up and mysql is ready for taking queries?](https://stackoverflow.com/questions/25503412/how-do-i-know-when-my-docker-mysql-container-is-up-and-mysql-is-ready-for-taking) – ikyuchukov Dec 08 '21 at 14:33

0 Answers0