论坛首页 Java企业应用论坛

MySQL数据库连接慢的问题解决办法

浏览 8184 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2008-11-24  

今天有一台MySQL数据库发现无论用JDBC去连接还是用Navicat等客户端去连接,都很慢,即便连接上了对数据操作和查询也都很慢,Google了一下,发现在my.ini文件中加入以下语句即可解决问题:

[mysqld]
skip-name-resolve 

 不知道因为什么缘故,特记录一下。

   发表时间:2008-11-24   最后修改:2008-11-24
看了你的问题,感觉好奇,我也去查了一下资料。设置这个参数,主要是跳过mysql的dns解析这个步骤。具体的我引用了一段:
When a new thread connects to mysqld, mysqld will spawn a new thread to handle the request. This thread will first check if the hostname is in the hostname cache. If not the thread will call gethostbyaddr_r() and gethostbyname_r() to resolve the hostname.

If the operating system doesn't support the above thread-safe calls, the thread will lock a mutex and call gethostbyaddr() and gethostbyname() instead. Note that in this case no other thread can resolve other hostnames that is not in the hostname cache until the first thread is ready.

You can disable DNS host lookup by starting mysqld with --skip-name-resolve. In this case you can however only use IP names in the MySQL privilege tables.
If you have a very slow DNS and many hosts, you can get more performance by either disabling DNS lookop with --skip-name-resolve or by increasing the HOST_CACHE_SIZE define (default: 128) and recompile mysqld.

You can disable the hostname cache with --skip-host-cache. You can clear the hostname cache with FLUSH HOSTS or mysqladmin flush-hosts.

If you don't want to allow connections over TCP/IP, you can do this by starting mysqld with --skip-networking.
0 请登录后投票
   发表时间:2008-11-25  
name-resolve  

这个问题很多软件都有这个问题, 比如SSH,  老外不知道怎么想的, 为什么不是default false. 遇见很多次了.
0 请登录后投票
   发表时间:2008-11-25  
hosts 加ip
0 请登录后投票
   发表时间:2008-12-02  
imjl 写道

hosts 加ip

Sun的AccessManager也有这个问题,上次我就是hosts加ip解决的。
0 请登录后投票
   发表时间:2008-12-23  
我做的微型系统,第一次用户登陆或是查询数据库,反应都很慢。
不知道什么原因啊。
0 请登录后投票
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics