Re: Handling death of mysqld

From: The Natural Philosopher <tnp_at_invalid.invalid>
Date: Tue, 23 Jan 2018 21:39:13 +0000
Message-ID: <p48a21$sk$1_at_dont-email.me>


[Quoted] On 23/01/18 21:27, Axel Schwenke wrote:
> On 23.01.2018 22:01, 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

>
>> I would have assumed that the
>> underlying C libraries would reconnect to the server

>
> If your program uses libmysqlclient (aka Connector C) then it can reconnect
> automatically. This feature was enabled by default in the past but in 5.0.3
> that changed to disabled. If it is enabled and the communication fails due
> to a network error, the client reconnects automatically.
>
> https://dev.mysql.com/doc/refman/5.7/en/c-api-auto-reconnect.html
>
"If auto-reconnect is enabled, the library tries once to reconnect to [Quoted] the server and send the statement again"

Once isn't going to be enough though, is it?

[Quoted] But you did make me aware of mysql_ping() which looks like a way to test if the server is in fact there, before executing the query...

[Quoted] I am thinking that

while mysql_ping(&mysql)

	{
	sleep (1);
	mysql_real_connect(&mysql,"127.0.0.1",
		DBUSER,DBPASS,DBNAME,0,"",0);
	}

mysql_query(............

should in fact simply stall the program until a valid connection is restablished?

-- 
There is something fascinating about science. One gets such wholesale 
returns of conjecture out of such a trifling investment of fact.

Mark Twain
Received on Tue Jan 23 2018 - 22:39:13 CET

Original text of this message