Bug #24933 Lost connection to MySQL server during query with users have a lot connections
Submitted: 9 Dec 2006 11:18 Modified: 15 Jan 2007 12:33
Reporter: Toan Dang Email Updates:
Status: Not a Bug Impact on me:
Category:MySQL Server Severity:S1 (Critical)
Version:5.0.30, 4.1.21 OS:Linux (Centos 4.3)
Assigned to: CPU Architecture:Any

[9 Dec 2006 11:18] Toan Dang
For more than 1 weeks I’ve been trying to find a solution to the error I kept receiving when doing a basic query to MySQL through script shell. I connect to mysql through SSH on web server. If I use the user for web server connect to mysql database to excute some basic query database, for example: use database or select * from... it kept returning back to me “Error 2013: Lost connection to MySQL server during query” with some user. (I have about 200 user connect to web server, in my.cnf I declare max_user_connections=600, max_connection=600, and max_timeout=3600, max_allow_packet: 512M, wait_timeout=3600). But if I use root user to connect and query, there is no error occur.
On the mysqld.log, I got a lots of errors: /var/lib/mysqld: error: Sort aborted.
I try to create another user and use to connect, there is no error.
I grant all privileges to that user and increase net_read_timeout, net_write_timeout,.. but can not solve problem.

I use more than 1 databases for website.
On website, some time it can not get data from database on some tables and some time I get error: Lost connection to MySQL during query or Fata error, can not connect to database...

Right away I went to my PHP, MySQL and Apache logs to find more information but nothing. I came back with nothing more than the error message I already received. So as I usually do off I went to Google for some help. Neither were leading into any direction to a solution. Even after finding the MySQL documentation talking about the “Lost Connection” or “server has gone away” error I didn’t find a solution.

Is it MySQL bug with the user have a lot of connections? How can I fix that problem? I have spent a lot of time for this problem. Our website provide news online so this error is terrible.
Please help me urgent.
PS: I use Centos 4.3 and use MySQL rpm version 4.1.21 supported on Centos 4.3.
Dell server with 4GB RAM, Core 2 Dual 4 CPU 2.8Mhz.

How to repeat:
when do query command line about 5 seconds
[9 Dec 2006 13:56] Valeriy Kravchuk
Thank you for a problem report. Please, send your my.cnf file content and last part of error log (for the day when you have this problem), or entire error log. You can upload error log as compressed file.
[9 Dec 2006 14:09] Toan Dang
This is my.cnf file of database, please see for more detail.

# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).







======================= mysqld.log============
0611209 11:53:33 [ERROR] /usr/libexec/mysqld: Sort aborted
0611209 11:53:34 [ERROR] /usr/libexec/mysqld: Sort aborted
0611209 11:53:56 [ERROR] /usr/libexec/mysqld: Sort aborted
0611209 11:53:56 [ERROR] /usr/libexec/mysqld: Sort aborted 
............... many lines sort aborted..........

=======Show Status========
Big abort connections

Thanks for your help.
[14 Dec 2006 21:30] Valeriy Kravchuk
These was the most importnat in your initial report, it seems:

"But if I use root user to connect and query, there is no error occur."

Please, read the manual, http://dev.mysql.com/doc/refman/4.1/en/too-many-connections.html. You just used all your connections (or have simple out of memory issue while sorting data). Send SHOW PROCESSLIST results got as root as soon as you'll see this problem again.
[15 Dec 2006 3:32] Toan Dang
Mysql status & Process log

Attachment: status_process.txt (text/plain), 15.37 KiB.

[15 Dec 2006 3:34] Toan Dang
Our company website have more than 10 modules and 6 databases. Use only one user for all connections. I increase max_user_connections=1000
max_connections=1000 but still can not solve the problems. I sure there are about 150 (max:300) user connections concurrent on website. 
Until now, I solve this problem by separate each module have 1 user connection. I create 10 user connection for 10 modules and now, losting data on the website no happen. But Sort aborted and Lost connection to MySQL during query are still happen a lots. 
But in the future, when one module have more connection, I think the problem will come back. I am not sure this is the best solution.
Please see the log file attach.
Thank for your help
Toan Dang
[15 Dec 2006 5:49] Valeriy Kravchuk
Is this prosesslist you attached really got while you have Lost connection/Sort aborted errors happening? Please, confirm.
[2 Jan 2007 6:46] Toan Dang
File of processlist & status mysql

Attachment: status_process.txt (text/plain), 10.26 KiB.

[2 Jan 2007 6:56] Toan Dang
Dear Mr.Valeriy Kravchuk
Sorry for reply late.
My company bought MySQL 5 Enterprise, I install on new server (Dell 6850, 16GB, 4 CPU Dual Core 2.8GH) but can not solve the problem.
Sometime, the problem must be occur.
The attach file is mysql processlist and status, please view it for more detail.
Thanks for all help.

Toan Dang
[2 Jan 2007 9:01] Valeriy Kravchuk
Hi Toan,

If you are a customer already, we have to discuss your problems in frames of support issue. Please, open a new one (you had to get email explaining how to do it) or just send your company name/contract number here (as private comment), and I'll create issue for you.
[8 Jul 2008 8:57] Stanislav Slavov
Same problem here too many "[ERROR] /usr/libexec/mysqld: Sort aborted" and application and mysql hangs. We use MySQL 5.0.51b
Our problem was not freeing result. I suggest you use trace mode to view query errors. If you use PHP with MySQL there is an option in php.in "mysql.trace_mode = Off" and you should change it to "On".
That helped us a lot to solve the problem. I think your configuration seems OK. I`m not a DBA and not very advanced in administration.
Hope that will help!