I am currently developing a C++ project that is required to connect to a MySQL database stored on another machine on the LAN network.
Connecting to the database works fine, I can run some queries no problem, but at the same point within a loop iterating the results (on the third iteration) the database connection closes, and the error I am given is:
MySQL server has gone away.
When I checked the server logs I see:
Aborted connection to db <user details> (Got an error reading communication packets)
After searching this site as well as Google, many posts suggest increasing several buffers and timeout variables:
innodb_log_buffer_size = 32M
innodb_log_file_size = 2047M
innodb_fast_shutdown = 0
max_connections = 400
connect_timeout = 300
net_read_timeout = 6000
net_write_timeout = 6000
wait_timeout = 9999999999
interactive_timeout = 9999999999
max_allowed_packet = 500M
net_buffer_length = 500M
I am iterating the results like so:
while( this->pRes->next() ) // pRes is a pointer to a sql::ResultSet instance
{
...
There have been several others with this issue, but the solution(s) that have worked for them have not been successful for me. Links to the questions are here:
ERROR 2006 (HY000): MySQL server has gone away
MySQL error 2006: mysql server has gone away
https://dba.stackexchange.com/questions/40899/mysql-error-reading-communication-packets
https://www.percona.com/blog/2016/05/16/mysql-got-an-error-reading-communication-packet-errors/
http://dev.mysql.com/doc/refman/5.7/en/communication-errors.html
Notes:
Closing the connection, and attempting to re-open it does not solve the issue. Calling sql::Connection::reconnect does not work either.
I have tried several values for the variables as different posts suggest different values, and every time I change something to try it out I have restarted the server.
The server version is 5.7, and MySQL Connector/C++ version is 1.1.7
There are more links to posts where people have posted the same issue, but generally they are just suggesting the same thing with different values to the variables I have listed (tried all and none work).
The machine hosting the server is Windows 10 Pro x64, and the machine I am developing on is also Windows 10 x64.
My development environment is Visual Studio 2015 Community
Firewalls are disabled on both machines, and the relevant tcp port on the router has been forwarded to the machine running the server
If you require more information, then please comment and I will provide what I can.