View Full Version : MySQL hostname resolution issues

September 30th, 2009, 01:03 AM
I'm working with some legacy (i.e. very bad) PHP code that makes connections to multiple MySQL servers, each on port 3306. In my local dev environment, I'm binding separate instances of MySQL to different loopback interfaces. (e.g.,, etc)

Everything works fine on the networking side. I can resolve the name, and I can open a connection...

$ resolveip rajah-slave
IP address of rajah-slave is

$ nmap rajah-slave -p 3306

Starting Nmap 4.76 ( http://nmap.org ) at 2009-09-29 16:47 PDT
Interesting ports on rajah-slave (
3306/tcp open mysql

Nmap done: 1 IP address (1 host up) scanned in 0.07 seconds

$ netstat -ln | grep 3306
tcp 0 0* LISTEN
tcp 0 0* LISTEN
tcp 0 0* LISTEN
tcp 0 0* LISTEN

... but MySQL chokes when resolving the hostname.

$ mysql -h rajah-slave
ERROR 2005 (HY000): Unknown MySQL server host 'rajah-slave' (-1)

$ mysql -h
Welcome to the MySQL monitor. Commands end with ; or \g.

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

Any guesses as to why this doesn't work? I'm stumped! ](*,)

September 30th, 2009, 01:40 AM
Okay, so hostname resolution in the mysql client dies a painful (and silent) death if any line in /etc/hosts is too long.

Problem solved!