Mysql – can’t connect to MySQL from localhost on Centos 5

centos5configurationdomain-name-systemMySQL

I have a fresh install of Centos 5.5 on a new VPS and MySQL seems unable to resolve the keyword 'localhost' – if I use 127.0.0.1 instead it works fine. I checked the /etc/hosts file which is as follows:

# Auto-generated hostname. Please do not remove this comment.
xxx.xxx.xxx.xxx 224136.xxxxxxxx.com localhost 224136  224136 localhost.localdomain
127.0.0.1       localhost

(I added the last line myself)…but still the localhost keyword isn't recognised. For example when I try to connect to my MySQL server using Navicat over SSH tunnel I get an error:

1130 - Host 'xxx.xxx.xxx.xxx' is not allowed to connect to this MySQL server

any ideas what might be the problem, thanks

Best Answer

Just for the sake of ruling MySQL is the culprit, please make sure you have root@localhost and root@127.0.0.1 as separate users defined in MySQL.

Do the following to make sure root users can come into MySQL:

SHOW GRANTS FOR 'root'@'localhost';
SHOW GRANTS FOR 'root'@'127.0.0.1';

root@localhost connects via the mysql.sock file

root@l127.0.0.1 connects via TCP/IP

Until you get the networking issues straightened out, you may want to use the --protocol option of the mysql client to specify the protocol (tcp,socket,pipe,memory)