教学之友,学习之友。

站长教学网

当前位置: 站长教学网 > 数据库 > MYSQL教程 >

连接独立远程mysql速度慢的解决方法

时间:2013-01-23 12:38来源:未知 作者:ken 点击:

skip-name-resolve取消DNS的反向解析

PHP远程连接MYSQL速度慢,有时远程连接到MYSQL用时4-20秒不等,本地连接MYSQL正常,出现这种问题的主要原因是,默认安装的 MYSQL开启了DNS的反向解析,在MY.INI(WINDOWS系统下)或MY.CNF(UNIX或LINUX系统下)文件的[mysqld]下加入 skip-name-resolve这一句。

但是,这样会引起一个问题:连接mysql时,不能使用 localhost连接了,而是要使用IP地址的;如果是按localhost对用户赋权限的话,用户登录权限也要修改一下的。

解决方法:

[mysqld]
skip-name-resolve

在mysqld中加上skip-name-resolve,重起mysql就OK了。

这样也会产生问题,

GRANT ALL ON test.* TO dba@localhost

这里的localhost是域名,这样的话就不能在MySQL的授权表中使用主机名了而只能用ip格式。

[mysqld]
skip-grant-tables

若使用–skip-grant-tables系统将对任何用户的访问不做任何访问控制,但可以用 mysqladmin flush-privileges或mysqladmin reload来开启访问控制;默认情况是show databases语句对所有用户开放,

如果mysql服务器没有开远程帐户,就在my.ini里面加上skip-grant-tables

附录:( How MySQL uses DNS ) 站长教学网 eduyo.com

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.

 

(责任编辑:ken)
TAG标签: mysql
顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
注册登录:不允许匿名留言,登录后留言无需输入验证码。
栏目列表
最新内容