连接MySql速度慢的解决方法(skip-name-resolve)
最近在linux服务器上安装mysql5后,本地使用客户端连mysql速度超慢,本地程序连接也超慢。
解决方法:在配置文件my.cnf的[mysqld]下加入skip-name-resolve。
原因是默认安装的mysql开启了dns的反向解析。如果禁用的话就不能在mysql的授权表中使用主机名了而只能用ip格式。
附:how mysql uses 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 lookup 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.
或者host中添加
192.168.1.21 n-21
上一篇: java验证电话号码的方法
推荐阅读
-
MySQL 5.0.16乱码问题的解决方法
-
用于App服务端的MySQL连接池(支持高并发)
-
MySQL4 File ‘c:\mysql\share\charsets\?.conf’ not found (Errcode: 22)的解决方法
-
java实现的连接oracle/mysql数据库功能简单示例【附oracle+mysql数据库驱动包】
-
MySQL提示The InnoDB feature is disabled需要开启InnoDB的解决方法
-
mysql报错:MySQL server version for the right syntax to use near type=InnoDB的解决方法
-
MySQL批量插入和唯一索引问题的解决方法
-
详解远程连接Mysql数据库的问题(ERROR 2003 (HY000))
-
MySQL恢复中的几个问题解决方法
-
MySQL启动连接的命令以及与PHP程序连接的基本语法