My application needs to do quite frequent connects to a mysql database on another machine. However I get frequent errors on connection; I can usually eventually connect but after many retries. The error message I get is:
Mysql.mysql(): Couldn't connect to SQL-server: Lost connection to MySQL server at 'reading authorization packet', system error: 2
I have read the information here: http://dev.mysql.com/doc/refman/5.0/en/error-lost-connection.html and also the comments to the bug http://bugs.mysql.com/bug.php?id=28359.
There are quite a number of aborted connects as you can see:
mysql> SHOW GLOBAL STATUS LIKE 'Aborted_connects'; +------------------+-------+ | Variable_name | Value | +------------------+-------+ | Aborted_connects | 2540 | +------------------+-------+
I increased the timeout from 5 to 15 sec:
mysql> show variables like 'connect_timeout'; +-----------------+-------+ | Variable_name | Value | +-----------------+-------+ | connect_timeout | 15 | +-----------------+-------+
but this has not helped. Any suggestions how to debug this ? It makes the database interaction horribly slow when it on average has to try to connect 5 times before it works.
I have not yet tried to keep the connection open for the lifetime of the application, would that be better ? How do I prevent the connection from closing ?
If it helps the computer with the problems is Windows 7 32-bit, while the mysql server is on Debian Linux.