I think you need to alter the server's configuration for that. The client can do nothing about it, at least not through the API. You can always keep the connection alive by sending fake requests, but that's not really a solution. You might search MySQL forums for keepalive solutions, I see there are some threads about it.