MySQL problem : Lost connection to MySQL server at ‘reading initial communication packet’

We recently encountered a problem with mysql installation that I think might be something that other people may get in trouble with too.

Essentially after installing mysql you can connect using mysql -p -u root but not using mysql -p -u root -h even though your mysql is listening on

netstat -tapn|grep mysql

tcp        0      0*               LISTEN      16212/mysqld

Problem is very simple but difficult to detect, somewhere along the line default behaviour have changed and now mysql needs to be able to read /etc/hosts.allow and /etc/hosts.deny if any of the files is inaccessible all incoming connections are rejected, earlier the default behaviour was to treat the files as they are empty in case they do not exist and allow the connection.

In our case mysql didn’t have permissions to read /etc/hosts.deny and because of it it was rejecting all connections done over tcp/ip

the solution was quite simple:

chmod a+r /etc/hosts.deny

of course you can make it more secure by limiting it to the specific group but I don’t see how being able to read a host.deny file might compromise the security, especially if the file is empty and that is all that is required for mysql to work: empty hosts.deny file

I hope it helped someone