MySql lost connection[SOLVED]

  • Hello.
    I works with pair of MAR + MySQL and when during long time there are no any queries to database, and then there is one I have in my MAR console log output like this
    Lost connection to MySQL server during query QMYSQL: Unable to execute query MySQL server has gone away QMYSQL.
    I tried set up mysql option "MYSQL_OPT_RECONNECT=true;", than I reopened database when I got any error with it executing, but nothing of this was succeed.

    I know that there is way using timer and make "select 1 from AnyTable" for persistence of mysql connection, but it looks like some kind of hack.

    May be anyone know some elegant solution of this problem ?

  • After opening your connection, run the following query

    QSqlQuery::exec("SET wait_timeout = 3600")

    Time in seconds.

  • @Leonardo sorry but I didn't caught.
    When my app start, I create some connections and I want to make them forever persistent and independent from idle live of connection.
    So as I understood wait_timeout var defines time of connection existing

  • Hi. I don't think it's possible to make a connection live forever without some sort of pinging as you said, but setting the wait_timeout variable can keep it alive for a lot of time. Please, see

    With a maximum value of 31536000 seconds, your connection can live for 1 whole year. Do you expect it to be idle for longer than that?

    There has to be a timeout, otherwise you would get a lot of dangling connections on your server, as it wouldn't be able to drop them for inactivity.

  • @Leonardo thank you very much. Now this problem is more clear for me

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.