Re: Handling death of mysqld

From: Lew Pitcher <lew.pitcher_at_digitalfreehold.ca>
Date: Tue, 23 Jan 2018 16:32:25 -0500
Message-ID: <p489l8$s8h$1_at_dont-email.me>


The Natural Philosopher wrote:

>
> This one caught mne out during a routine upograde of the mysql server -
> the server was killed and restarted.
>
>
> One of my programs failed to handle this gracefully: It is a piped
> program that takes log data from apache and injects it into the database
> for traffic and usage analysis.
>
> It is very simple. It opens the databsae, never closes it, and executes
> insert/update on duplicate statements several times a second typically.
>
> Obviously at some point these failed, but I would have assumed that the
> underlying C libraries would reconnect to the server once it came up,

The (now deprecated) PHP "mysql_query()" function apparently attempts to do that, but (AFAICT), the C API does not.

> and these inserts would resume. It semmes not
>
> I had to restart the apache server to respean the pipe and re open thet
> database.
>
> What error does mysql_query() return in such a case,

I would expect that, instead of the zero returncode for success, mysql_query() would return either
  CR_SERVER_GONE_ERROR
indicating that the "MySQL server has gone away", or   CR_SERVER_LOST
indicating that "the connection to the server was lost during the query".

> so I know that its
> happened and can go into 'sleep, and reconnect' mode?

HTH

-- 
Lew Pitcher
"In Skills, We Trust"
PGP public key available upon request
Received on Tue Jan 23 2018 - 22:32:25 CET

Original text of this message