Troubleshooting Slow MySQL Remote Connections: DNS Lookup and Authentication Delays


2 views

When connecting remotely to a MySQL 5.0.75 server from another machine in the same local network, the connection establishment takes an unusually long 5-6 seconds:

mysql -h 172.22.65.101 -u myuser -p123

Ping tests show the network latency is minimal (avg 1.959ms), eliminating network issues as the root cause:

PING 172.22.65.101 (172.22.65.101) 56(84) bytes of data.
64 bytes from 172.22.65.101: icmp_seq=1 ttl=64 time=0.799 ms
[...]
rtt min/avg/max/mdev = 0.000/1.959/6.437/2.383 ms

Monitoring with SHOW PROCESSLIST reveals the connection hangs at the "unauthenticated user" state before finally authenticating. This points to potential:

  • DNS reverse lookups
  • Authentication plugin delays
  • Hostname resolution issues

Add these parameters to your my.cnf under the [mysqld] section:

[mysqld]
skip-name-resolve
skip-host-cache

To measure the actual connection time:

time mysql -h 172.22.65.101 -u myuser -p123 -e "SELECT 1"

If still experiencing delays, consider:

# 1. Use IP addresses in grant tables
GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'172.22.65.%' IDENTIFIED BY '123';

# 2. Check for IPv6 issues
bind-address = 0.0.0.0

Enable the MySQL slow query log for connection attempts:

[mysqld]
log_slow_verbosity=full
log_warnings=2

Then monitor the log for connection-related warnings.

Your client (5.0.51a) and server (5.0.75) versions should be compatible, but consider upgrading to a supported version if possible.


When establishing remote connections to my MySQL 5.0.75 server from a local network machine, I encountered an unusual 5-6 second delay during authentication phase. The ping times showed normal network latency (avg 1.959ms), eliminating network issues as the root cause.

Monitoring with SHOW PROCESSLIST revealed the connection remains in "unauthenticated user" state before finally authenticating. Key environmental details:

Server Version: mysql  Ver 14.12 Distrib 5.0.75
Client Version: mysql  Ver 14.12 Distrib 5.0.51a
Network: Local LAN (172.22.65.0/24)
Ping: 0-6.43ms latency

The delay occurs during DNS reverse lookup and authentication mechanism negotiation. MySQL performs several operations during this phase:

  • DNS resolution of client IP
  • Authentication plugin negotiation
  • Credential verification
  • Session initialization

Modify your my.cnf to include these performance-critical parameters:

[mysqld]
skip-name-resolve
skip-host-cache
# For MySQL 5.0 enable old_passwords if needed
old_passwords=0
# Adjust thread settings
thread_cache_size = 16
# Connection timeout
connect_timeout = 10
wait_timeout = 28800
interactive_timeout = 28800

To confirm network isn't the issue, test with:

# Basic network test
time nc -zv 172.22.65.101 3306

# MySQL protocol test
time mysql -h 172.22.65.101 -u myuser -p123 -e "SELECT 1"

MySQL 5.0 uses older authentication mechanisms that can cause delays. Verify with:

SHOW VARIABLES LIKE 'old_passwords';
SHOW VARIABLES LIKE 'secure_auth';

For development environments, consider using a connection pooler like ProxySQL:

# ProxySQL basic config
INSERT INTO mysql_servers(hostgroup_id,hostname,port) VALUES (10,'172.22.65.101',3306);
INSERT INTO mysql_users(username,password,default_hostgroup) VALUES ('myuser','123',10);
LOAD MYSQL SERVERS TO RUNTIME;
SAVE MYSQL SERVERS TO DISK;