Monday, June 28, 2010

MySQL DNS woes

Today I was trying to bring up a mysql instance to begin setting up a mysql cluster and faced a strange problem. I was unable to connect to mysql/mysqladmin giving the host option both on the box where mysql is installed and from another box with just the client.
root@lucid-myndbmgr# mysqladmin version
mysqladmin  Ver 8.42 Distrib 5.1.39-ndb-7.0.9, for debian-linux-gnu on i486
Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under GPL license

Server version      5.1.39-ndb-7.0.9-1ubuntu7
Protocol version    10
Connection     Localhost via UNIX socket
UNIX socket     /var/run/mysqld/mysqld.sock
Uptime      24 min 57 sec
Thread: 1  Questions: 7  Slow queries: 0  Opens: 15  Flush tables: 1  Open tables: 8  Queries per second avg: 0.4   
root@lucid-myndbmgr# ifconfig eth0
eth0       Link encap:Ethernet  HWaddr 08:00:27:1d:ed:e8
       inet addr:10.0.0.2  Bcast:10.0.0.255  Mask:255.255.255.0
       inet6 addr: fe80::a00:27ff:fe1d:ede8/54 Scope:Link
       UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
       RX packets: 22 errors:0 dropped:0 overruns:0 frame:0
       TX packets: 21 errors:0 dropped:0 overruns:0 carrier:0
       ncollisions:0 txqueuelen:1000
       RX bytes:3294 (3.2 KB)  TX bytes:2136 (2.1 KB)
       Interrupt:10 Base address:0xd020

root@lucid-myndbmgr# mysqladmin ping
mysqld is alive
root@lucid-myndbmgr# hostname
lucid-myndbmgr
root@lucid-myndbmgr# grep 'bind-address' /etc/mysql/my.cnf
bind-address       = 10.0.0.2
root@lucid-myndbmgr# netstat -an | grep 3306
tcp       0       0   10.0.0.2:3306  0.0.0.0:* LISTEN
root@lucid-myndbmgr# mysqladmin -h 10.0.0.2 ping
mysqladmin: connect to server at '10.0.0.2' failed
error: 'Can't get hostname for your address'
After some furious googling and some wisdom from #mysql I figured out that mysql requires a functional DNS to work (I still haven't figured out why my DNS config is getting ignored :(..). Initial suggestions were to open up port 3306, remove bind-address and do not use skip-networking. They din't help
root@lucid-myndbmgr# iptables -A INPUT -p tcp --dport 3306 -s 0/0 -j ACCEPT
root@lucid-myndbmgr# iptables -A OUTPUT -p tcp --sport 3306 -d 0/0 -j ACCEPT
root@lucid-myndbmgr# iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination
ACCEPT    tcp --  anywhere   anywhere  tcp dpt:mysql

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination
ACCEPT    tcp --  anywhere   anywhere tcp spt:mysql
root@lucid-myndbmgr# grep 'bind-address\|skip-networking' /etc/mysql/my.cnf
# Instead of skip-networking the default is now to listen only on
#bind-address       = 10.0.0.2
root@lucid-myndbmgr# mysqladmin -h 10.0.0.2 ping
mysqladmin: connect to server at '10.0.0.2' failed
error: 'Can't get hostname for your address'
So, as a workaround found skip-name-resolve parameter which conveniently skips this.
root@lucid-myndbmgr# grep 'skip-name-resolve' /etc/mysql/my.cnf
skip-name-resolve
root@lucid-myndbmgr# mysqladmin -h 10.0.0.2 ping
mysqld is alive
root@lucid-myndbmgr# 

No comments: