与MySQL服务器的远程连接需要很长时间


10

我的Linux笔记本上有一个运行MySQL 5.0.75的服务器,我想从本地网络中的另一台计算机连接到该服务器。

此连接需要5到6秒钟:

mysql -h 172.22.65.101 -u myuser -p123

对MySQL主机的ping操作:

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
64 bytes from 172.22.65.101: icmp_seq=2 ttl=64 time=0.000 ms
64 bytes from 172.22.65.101: icmp_seq=3 ttl=64 time=6.43 ms
64 bytes from 172.22.65.101: icmp_seq=4 ttl=64 time=0.000 ms
64 bytes from 172.22.65.101: icmp_seq=5 ttl=64 time=3.81 ms
64 bytes from 172.22.65.101: icmp_seq=6 ttl=64 time=0.706 ms
^C
--- 172.22.65.101 ping statistics ---
6 packets transmitted, 6 received, 0% packet loss, time 5027ms
rtt min/avg/max/mdev = 0.000/1.959/6.437/2.383 ms

有任何想法吗?当我用SHOW PROCESSLIST监视连接时;在MySQL主机上,我可以看到该命令是“ connect”,该用户是“未经身份验证的用户”。这一直持续到建立连接为止。(用户随后显示为“ myuser”,命令为“ sleep”)

我是一名开发人员,需要您提供有关如何找到瓶颈的建议!

主机上的my.cnf:

[client]
port = 3306
socket = /var/run/mysqld/mysqld.sock

[mysqld_safe]
socket = /var/run/mysqld/mysqld.sock
nice  = 0

[mysqld]
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
key_buffer = 16M
max_allowed_packet = 16M
thread_stack = 128K
thread_cache_size = 8
myisam-recover = BACKUP
query_cache_limit = 1M
query_cache_size = 16M
expire_logs_days = 10
max_binlog_size = 100M
skip-federated

[mysqldump]
quick
quote-names
max_allowed_packet = 16M

[isamchk]
key_buffer = 16M

客户:

mysql  Ver 14.12 Distrib 5.0.51a, for debian-linux-gnu (i486) using readline 5.2

服务器:

mysql  Ver 14.12 Distrib 5.0.75, for debian-linux-gnu (i486) using readline 5.2

Answers:


17

可能是您在尝试检索和验证连接主机的反向DNS时滞后。您可以通过打开skip_name_resolve服务器的my.cnf [mysqld]部分来对此进行测试。

如果确实是这种情况(通过消除延迟的该参数演示),则可以通过为客户端正确设置DNS(正向和反向)或skip_name_resolve始终运行来解决问题(这意味着您可以在GRANT表中不使用主机名)。


修好了!我在MySQL主机的my.cnf中定义了skip_name_resolve,重启了MySQL,问题得以解决。我欠你一些啤酒。:)
Lennart

很高兴能为您服务。:)
混乱

1
太好了谢谢!只是要清楚一点(以防万一有人把我弄乱了),它只是在一行上“ skip_name_resolve”,而不是“ skip_name_resolve = 1”或其他任何东西,否则您的服务将无法启动!
James Crowley 2010年
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.