MySQL Forums
Forum List  »  Connector/C (libmysql)

mysql can't excute 'init commands' when reconnecting after timeout.
Posted by: me mi
Date: May 22, 2015 08:08PM

Mysql version is 5.6 and using mysql C API:

I want to reconnect mysql server automically after one connection is timeout, and excute some sql statements automically when the reconnection succeeds, so I write like this:

MYSQL* my_sql = mysql_init(NULL);
int reconnect = 1;
mysql_options(my_sql, MYSQL_OPT_RECONNECT, (void*)&reconnect);
mysql_options(my_sql, MYSQL_INIT_COMMAND, "set names gbk;");
mysql_real_connect(...);

The first excution is ok: it can connect to server and get right contents after mysql_query. Ater a long time (ensure the connection is timeout) and excute the mysql_query agin, mysql_query can excute successfully and gets a result set, so the "MYSQL_OPT_RECONNECT" option must works, but "MYSQL_INIT_COMMAND" option does not work, because the result contents in result set have wrong format and can not be recognized like '? ?* @ '.

Even if I use CLIENT_REMEMBER_OPTIONS with mysql_real_connect ,the result contents got by mysql_query is right when not timeout ,but wrong when timeout:
mysql_real_connect(..., CLIENT_REMEMBER_OPTIONS).

Could somebody tell me the reason ? Thanks very much!

Options: ReplyQuote


Subject
Views
Written By
Posted
mysql can't excute 'init commands' when reconnecting after timeout.
1492
May 22, 2015 08:08PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.