Intermittent 'waiting for initial communication packet', system error: 95

MySQL version: 5.5.28-0ubuntu0.12.04.2-log

I just upgraded my 64-bit server from Ubuntu 10.04 to 12.04.1 not quite a month ago. Since then, this issue has come up a few times in the Apache error log and no other logs seem to have any entries pointing to a cause:

PHP Warning: mysql_connect(): Lost connection to MySQL server at ‘waiting for initial communication packet’, system error: 95

And, naturally, this error follows:

PHP Warning: mysql_connect(): Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2)

A mysql restart solves it or it resolves itself after a few minutes, but I’d rather not have it happen at all.

I have a second server configured the exact same and it doesn’t have the issues, but it was upgraded over two months ago and doesn’t have the same user or data volume.

Some sites suggest changing the mysql wait_timeout value to a lower number than the default of 28800.

After this happened today, I ran mysqlcheck to check and auto-repair the tables, but it happened again about 8 hours later. During the last incident, I tried to connect to mysql from the command line (#mysql -u root -p), but couldn’t:

ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (111)

/var/run/mysqld/mysqld.sock was there, though. I checked before restarting.

Since I was there, I restarted Apache first to see if it was the culprit (unclosed handles), but it didn’t help. Could be a restart doesn’t pause long enough to close the handles.

This is getting serious. Does anyone have any suggestions?

Thanks,
Mike

PHP Warning: mysql_connect(): Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2)

That error means that the socket file doesn’t exist.

perror 2

OS error code 2: No such file or directory

ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (111)

This one means:

perror 111

OS error code 111: Connection refused

I recommend you to check if you have a firewall (iptables) or some security software (apparmor / selinux) enabled and running. Also the error log would be helpful here.

This manual page can help you to debug the problem:

http://dev.mysql.com/doc/refman/5.5/en/communication-errors. html (check the reference to connect_timeout variable)

Thanks for the response, miguelangelnieto.

During the last episode, the socket file was there and we have a Zabbix box that will alert me if mysql is not running, so mysql was still running during these episodes.

Apparmor is running. No iptables, but a strict hosts.allow/deny configuration.

I did look at the MySQL communication issues doc page before. I don’t currently have the query log enabled. Think I should or is the performance hit not worth it?

There’s nothing in the MySQL error log pointing to an issue during the time periods in question. The episode yesterday was at 16:36, so I restarted MySQL. There was a second instance at 18:10. There are no entries in between:

130102 16:36:54 InnoDB: Starting shutdown…
130102 16:36:56 InnoDB: Shutdown completed; log sequence number 86958942
130102 16:36:56 [Note] /usr/sbin/mysqld: Shutdown complete
130102 16:36:56 [Note] Plugin ‘FEDERATED’ is disabled.
130102 16:36:56 InnoDB: The InnoDB memory heap is disabled
130102 16:36:56 InnoDB: Mutexes and rw_locks use GCC atomic builtins
130102 16:36:56 InnoDB: Compressed tables use zlib 1.2.3.4
130102 16:36:56 InnoDB: Initializing buffer pool, size = 16.0M
130102 16:36:56 InnoDB: Completed initialization of buffer pool
130102 16:36:56 InnoDB: highest supported file format is Barracuda.
130102 16:36:56 InnoDB: Waiting for the background threads to start
130102 16:36:57 InnoDB: 1.1.8 started; log sequence number 86958942
130102 16:36:57 [Note] Server hostname (bind-address): ‘0.0.0.0’; port: 3306
130102 16:36:57 [Note] - ‘0.0.0.0’ resolves to ‘0.0.0.0’;
130102 16:36:57 [Note] Server socket created on IP: ‘0.0.0.0’.
130102 16:36:57 [Note] Event Scheduler: Loaded 0 events
130102 16:36:57 [Note] /usr/sbin/mysqld: ready for connections.
Version: ‘5.5.28-0ubuntu0.12.04.3-log’ socket: ‘/var/run/mysqld/mysqld.sock’ port: 3306 (Ubuntu)
130102 16:37:52 [Note] Start binlog_dump to slave_server(2), pos(mysql-bin.001195, 1715160)
130102 18:10:44 [Note] /usr/sbin/mysqld: Normal shutdown
130102 18:10:44 [Note] Event Scheduler: Purging the queue. 0 events
130102 18:10:46 [Warning] /usr/sbin/mysqld: Forcing close of thread 8572 user: ‘etherpad’
130102 18:10:46 [Warning] /usr/sbin/mysqld: Forcing close of thread 8571 user: ‘etherpad’
130102 18:10:46 [Warning] /usr/sbin/mysqld: Forcing close of thread 8570 user: ‘etherpad’
130102 18:10:46 [Warning] /usr/sbin/mysqld: Forcing close of thread 2612 user: ‘openmeetings’
130102 18:10:46 [Warning] /usr/sbin/mysqld: Forcing close of thread 2611 user: ‘openmeetings’
130102 18:10:46 InnoDB: Starting shutdown…
130102 18:10:47 InnoDB: Shutdown completed; log sequence number 86984114
130102 18:10:47 [Note] /usr/sbin/mysqld: Shutdown complete
130102 18:10:47 [Note] Plugin ‘FEDERATED’ is disabled.
130102 18:10:47 InnoDB: The InnoDB memory heap is disabled
130102 18:10:47 InnoDB: Mutexes and rw_locks use GCC atomic builtins
130102 18:10:47 InnoDB: Compressed tables use zlib 1.2.3.4
130102 18:10:47 InnoDB: Initializing buffer pool, size = 16.0M
130102 18:10:47 InnoDB: Completed initialization of buffer pool
130102 18:10:48 InnoDB: highest supported file format is Barracuda.
130102 18:10:48 InnoDB: Waiting for the background threads to start
130102 18:10:49 InnoDB: 1.1.8 started; log sequence number 86984114
130102 18:10:49 [Note] Server hostname (bind-address): ‘0.0.0.0’; port: 3306
130102 18:10:49 [Note] - ‘0.0.0.0’ resolves to ‘0.0.0.0’;
130102 18:10:49 [Note] Server socket created on IP: ‘0.0.0.0’.
130102 18:10:49 [Note] Event Scheduler: Loaded 0 events
130102 18:10:49 [Note] /usr/sbin/mysqld: ready for connections.
Version: ‘5.5.28-0ubuntu0.12.04.3-log’ socket: ‘/var/run/mysqld/mysqld.sock’ port: 3306 (Ubuntu)
130102 18:11:44 [Note] Start binlog_dump to slave_server(2), pos(mysql-bin.001196, 25606276)

For a first time, however, I did see a couple of entries in the error log when there wasn’t an episode. These entries only appeared last night, though:

130102 18:31:46 [Warning] Aborted connection 2824 to db: ‘openmeetings’ user: ‘openmeetings’ host: ‘localhost’ (Got an error reading communication packets)
130102 18:31:46 [Warning] Aborted connection 2826 to db: ‘openmeetings’ user: ‘openmeetings’ host: ‘localhost’ (Got an error reading communication packets)
130103 1:10:03 [Warning] Aborted connection 163224 to db: ‘openmeetings’ user: ‘openmeetings’ host: ‘localhost’ (Got an error reading communication packets)
130103 1:10:03 [Warning] Aborted connection 14759 to db: ‘openmeetings’ user: ‘openmeetings’ host: ‘localhost’ (Got an error reading communication packets)

There were no entries last night other than those four.