来源:http://bbs.chinaunix.net/thread-621473-1-1.html
查了下网络上出现该原因的来源如下:
This means that something of the following has happened:
The client program did not call mysql_close() before exit.
The client had been sleeping more than wait_timeout or interactive_timeout without doing any requests. See section SHOW VARIABLES.
The client program ended abruptly in the middle of the transfer.
When the above happens, the server variable Aborted_clients is incremented.
The server variable Aborted_connects is incremented when:
When a connection packet doesn't contain the right information.
When the user didn't have privileges to connect to a database.
When a user uses a wrong password.
When it takes more than connect_timeout seconds to get a connect package.
这个现象如果是因为有人想恶意连接你的数据库就无所谓了,只要加强安全控制就行了,如果是正常的连接情况下产生的,就要检查出真正的原因所在了。
有人建议:
请参阅:http://codenode.com/dns
解决办法:
1、启动时带参数 --skip-name-resolve
2、访问的主机授权时用IP,最好把该主机的IP及主机名写到/etc/hosts文件中
试过了还是不行,一样还会出现Aborted_connects大于0的情况,可能有人恶意连接我的数据库的原因,出现了Aborted_connects总出现大于0!
附录:
发现这算属MySQL的一个bug,不管连接是通过hosts还是ip的方式,MySQL都会对DNS做反查,IP到DNS,由于反查的接续速度过慢(不管是不是isp提供的dns服务器的问题或者其他原因),大量的查询就难以应付,线程不够用就使劲增加线程,但是却得不到释放,所以MySQL会“ 假死”。
解决的方案很简单,结束这个反查的过程,禁止任何解析。
打开mysql的配置文件(my.cnf),在[mysqld]下面增加一行:
skip-name-resolve
[mysqld]
skip-name-resolve
附录:( 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 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.
PHP远程连接MYSQL速度慢,有时远程连接到MYSQL用时4-20秒不等,本地连接MYSQL正常,出现这种问题的主要原因是,默认安装的MYSQL开启了DNS的反向解析,在MY.INI(WINDOWS系统下)或MY.CNF(UNIX或LINUX系统下)文件的[mysqld]下加入skip-name-resolve这一句。
MYSQL远程连接速度慢的解决方法
在局域网内连接其他机器的MYSQL,发现速度慢的很,不知道什么原因,总有几秒的延迟.
后来在网上发现解决方法,my.ini里面添加
[mysqld]
skip-name-resolve
skip-grant-tables
这样速度就快了!
skip-name-resolve
选项就能禁用DNS解析,连接速度会快很多。不过,这样的话就不能在MySQL的授权表中使用主机名了而只能用ip格式。
若使用–skip-grant-tables系统将对任何用户的访问不做任何访问控制,但可以用 mysqladmin flush-privileges或mysqladmin reload来开启访问控制;默认情况是show databases语句对所有用户开放,
如果mysql服务器没有开远程帐户,就在my.ini里面加上skip-grant-tables
我的处理,2步骤:
1.修改My.cnf
vi /etc/my.cnf
加入一行,直接绑定IP,如下:
没有重启动前端口是这样的,如下:
root@116.255.139.240:~# netstat -atlunp|grep mysql
tcp 0 0 :::3306 :::* LISTEN 24841/mysqld
重启Mysql:
root@116.255.139.240:~# cat /root/runmysql.sh
sh /root/runmysql.sh
启动后发现:
root@116.255.139.240:~# netstat -atlunp|grep mysql
tcp 0 0 116.255.139.240:3306 0.0.0.0:* LISTEN 10965/mysqld
2.修改Linux的host文件,目的是把localhost指向上面这个116.255.139.240,而不是127.0.0.1,否则会出现连接不上Mysql的,操作如下:
mysql的bind-address设置为127.0.0.1,通过localhost连接访问不了,所以必须修改!!!
root@116.255.139.240:~# vi /etc/hosts
#127.0.0.1 localhost.localdomain localhost jackxiang.localhost
116.255.139.240 localhost.localdomain localhost jackxiang.localhost
测试Mysql是否Ok:
mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 81
Server version: 5.5.20-log Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
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.
大致翻译如下:
当一个新连接连接mysql服务器时,mysql服务器会对此次连接的合法性进行判定,具体通过查询mysql.user表实现。mysql的权限设置将user和host(客户端的地址)联系起来,只有当两者都符合条件时才能进行下一步认证。
当 客户端连接的时候,客户端的地址假如不在mysql.host表中时,mysql服务器会调用gethostbyaddr和gethostbyname名 字进行解析(同步方法),或者gethostbyaddr_r和gethostbyname_r(异步)来解析客户端地址,这样会导致效率下降。
因此建议安装完毕之后从my.cnf中删除skip-name-resolve,然后在调用grant命令时全部写成ip地址。
假如以前的mysql.user表中host列存在host-name,设置skip-name-resolve时,会出现如下的warning:
[Warning] ‘user’ entry ‘root@XXX.com’ ignored in –skip-name-resolve mode.
删掉(因为已经改成ip认证的形式了)重启就ok了
查了下网络上出现该原因的来源如下:
This means that something of the following has happened:
The client program did not call mysql_close() before exit.
The client had been sleeping more than wait_timeout or interactive_timeout without doing any requests. See section SHOW VARIABLES.
The client program ended abruptly in the middle of the transfer.
When the above happens, the server variable Aborted_clients is incremented.
The server variable Aborted_connects is incremented when:
When a connection packet doesn't contain the right information.
When the user didn't have privileges to connect to a database.
When a user uses a wrong password.
When it takes more than connect_timeout seconds to get a connect package.
这个现象如果是因为有人想恶意连接你的数据库就无所谓了,只要加强安全控制就行了,如果是正常的连接情况下产生的,就要检查出真正的原因所在了。
有人建议:
请参阅:http://codenode.com/dns
解决办法:
1、启动时带参数 --skip-name-resolve
2、访问的主机授权时用IP,最好把该主机的IP及主机名写到/etc/hosts文件中
试过了还是不行,一样还会出现Aborted_connects大于0的情况,可能有人恶意连接我的数据库的原因,出现了Aborted_connects总出现大于0!
附录:
发现这算属MySQL的一个bug,不管连接是通过hosts还是ip的方式,MySQL都会对DNS做反查,IP到DNS,由于反查的接续速度过慢(不管是不是isp提供的dns服务器的问题或者其他原因),大量的查询就难以应付,线程不够用就使劲增加线程,但是却得不到释放,所以MySQL会“ 假死”。
解决的方案很简单,结束这个反查的过程,禁止任何解析。
打开mysql的配置文件(my.cnf),在[mysqld]下面增加一行:
skip-name-resolve
[mysqld]
skip-name-resolve
附录:( 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 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.
PHP远程连接MYSQL速度慢,有时远程连接到MYSQL用时4-20秒不等,本地连接MYSQL正常,出现这种问题的主要原因是,默认安装的MYSQL开启了DNS的反向解析,在MY.INI(WINDOWS系统下)或MY.CNF(UNIX或LINUX系统下)文件的[mysqld]下加入skip-name-resolve这一句。
MYSQL远程连接速度慢的解决方法
在局域网内连接其他机器的MYSQL,发现速度慢的很,不知道什么原因,总有几秒的延迟.
后来在网上发现解决方法,my.ini里面添加
[mysqld]
skip-name-resolve
skip-grant-tables
这样速度就快了!
skip-name-resolve
选项就能禁用DNS解析,连接速度会快很多。不过,这样的话就不能在MySQL的授权表中使用主机名了而只能用ip格式。
若使用–skip-grant-tables系统将对任何用户的访问不做任何访问控制,但可以用 mysqladmin flush-privileges或mysqladmin reload来开启访问控制;默认情况是show databases语句对所有用户开放,
如果mysql服务器没有开远程帐户,就在my.ini里面加上skip-grant-tables
我的处理,2步骤:
1.修改My.cnf
vi /etc/my.cnf
加入一行,直接绑定IP,如下:
没有重启动前端口是这样的,如下:
root@116.255.139.240:~# netstat -atlunp|grep mysql
tcp 0 0 :::3306 :::* LISTEN 24841/mysqld
重启Mysql:
root@116.255.139.240:~# cat /root/runmysql.sh
sh /root/runmysql.sh
启动后发现:
root@116.255.139.240:~# netstat -atlunp|grep mysql
tcp 0 0 116.255.139.240:3306 0.0.0.0:* LISTEN 10965/mysqld
2.修改Linux的host文件,目的是把localhost指向上面这个116.255.139.240,而不是127.0.0.1,否则会出现连接不上Mysql的,操作如下:
mysql的bind-address设置为127.0.0.1,通过localhost连接访问不了,所以必须修改!!!
root@116.255.139.240:~# vi /etc/hosts
#127.0.0.1 localhost.localdomain localhost jackxiang.localhost
116.255.139.240 localhost.localdomain localhost jackxiang.localhost
测试Mysql是否Ok:
mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 81
Server version: 5.5.20-log Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
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.
大致翻译如下:
当一个新连接连接mysql服务器时,mysql服务器会对此次连接的合法性进行判定,具体通过查询mysql.user表实现。mysql的权限设置将user和host(客户端的地址)联系起来,只有当两者都符合条件时才能进行下一步认证。
当 客户端连接的时候,客户端的地址假如不在mysql.host表中时,mysql服务器会调用gethostbyaddr和gethostbyname名 字进行解析(同步方法),或者gethostbyaddr_r和gethostbyname_r(异步)来解析客户端地址,这样会导致效率下降。
因此建议安装完毕之后从my.cnf中删除skip-name-resolve,然后在调用grant命令时全部写成ip地址。
假如以前的mysql.user表中host列存在host-name,设置skip-name-resolve时,会出现如下的warning:
[Warning] ‘user’ entry ‘root@XXX.com’ ignored in –skip-name-resolve mode.
删掉(因为已经改成ip认证的形式了)重启就ok了
作者:jackxiang@向东博客 专注WEB应用 构架之美 --- 构架之美,在于尽态极妍 | 应用之美,在于药到病除
地址:https://jackxiang.com/post/4930/
版权所有。转载时必须以链接形式注明作者和原始出处及本声明!
最后编辑: jackxiang 编辑于2012-2-26 12:40
评论列表
2012-2-2 09:13 | hxngb3kf
新年新气象,新春节日到!祝大家节日快乐!
分页: 1/1 1