MySQL : automatic reconnect?

Dear all,
Dear Sergey,

I have a program that connects to a MySQL database and will continue to live for a very long time. It can occur that there are more than 8h between queries to the server. As a consequence, I get the following error :
Error in TMySQLServer::Statement: Code: 2006 Msg: MySQL server has gone away

I tried to use PingVerify() on the server object to see what it does. It says :
Error in TMySQLServer::PingVerify: not able to automatically reconnect a second time
Error in TMySQLServer::Ping: Code: 2006 Msg: MySQL server has gone away
Ping verify : 0

My question is simple : how do I specify that I want an automatic reconnection ? I would need to call mysql_options(…, MYSQL_OPT_RECONNECT, …) but I can’t… Or I don’t see how.

Could you provide a wrapper method in TMySQLServer for mysql_options ?
Or at least an extended list of accepted parameters in the TMySQLServer object ?

Thanks in advance,
Barth

Hi Barth,

For the moment the way mysql options delivered via ROOT interface - additional arguments for TSQLServer::Connect operation. They are described in TMySQLServer constructor
root.cern.ch/root/html/TMySQLSer … ySQLServer

Unfortunately, there is no way to specify reconnect option MYSQL_OPT_RECONNECT. Actully, it was added only in MySQL version 5 after ROOT MySQL plugin was finished. I can easily add it. Have you other options that you missed?

Sergey

Hi Sergey,

Thanks for your very quick reply.

It is what I noticed, but I think this is a bit static in the sense that you have to modify source code each time there is a request to access a new option. Couldn’t you add a method that would wrap mysql_options ?

No, not as far as I can see.

Cheers,
Barth

Hi Barth,

There is no problem to provide wrapper for mysql_options function, but if you look in description here:

dev.mysql.com/doc/refman/5.0/en/ … tions.html

you see that mysql_options should be called BEFORE mysql_real_connect is called. Means you should set options before you create MySQLServer instance :frowning:. Therefore, with current concept of TSQLServer::Connect() it is not easy to provide that you want. I propose to add several options, like reconnect, as I did before. You also can use my.cnf file to set most options there.

Sergey

Hi Sergey,

You are right, I didn’t notice this. Thanks for checking.

Could you post a reply once the new option is available ?

Thanks again,
Barth

Hi Barth,

Changes are now in svn repository.
You can set reconnect attribute and also few more options.
See TMySQLServer constructor for more details.
I guess, most of other staff you can set via custom my.cnf file.

Regards,
Sergey