{"id":683,"date":"2010-08-18T23:09:24","date_gmt":"2010-08-18T15:09:24","guid":{"rendered":"http:\/\/gwokae.mewggle.com\/wordpress\/?p=683"},"modified":"2010-08-18T23:09:24","modified_gmt":"2010-08-18T15:09:24","slug":"ap%e9%81%a0%e7%ab%af%e9%80%a3%e6%8e%a5mysql-connection%e6%9a%b4%e5%a2%9e%e6%9c%80%e5%be%8c%e9%80%a0%e6%88%90error-1040-hy000-too-many-connections","status":"publish","type":"post","link":"https:\/\/gwokae.mewggle.com\/wordpress\/2010\/08\/ap%e9%81%a0%e7%ab%af%e9%80%a3%e6%8e%a5mysql-connection%e6%9a%b4%e5%a2%9e%e6%9c%80%e5%be%8c%e9%80%a0%e6%88%90error-1040-hy000-too-many-connections\/","title":{"rendered":"AP\u9060\u7aef\u9023\u63a5MySQL Connection\u66b4\u589e\u6700\u5f8c\u9020\u6210ERROR 1040 (HY000): Too many connections"},"content":{"rendered":"<p>PHP\u9023\u63a5\u9060\u7aefmysql server\u6700\u7d42\u9020\u6210ERROR 1040 (HY000): Too many connections<\/p>\n<p>\u6700\u8fd1\u9047\u5230\u4e00\u500b\u5f88\u8a6d\u7570\u7684\u554f\u984c\uff0c\u539f\u672c\u7684PHP\u7cfb\u7d71\u8981\u64f4\u589eAP Server\u4e26\u628aMySQL\u79fb\u5230\u4e00\u53f0\u7368\u7acb\u7684Server\u4e0a\u904b\u4f5c\uff0c\u539f\u672c\u8a8d\u70ba\u9019\u500btask\u5e7e\u4e4e\u662f\u6c92\u6709\u98a8\u96aa\u7684\uff0c\u6c92\u60f3\u5230\u4e00\u63a5\u4e0a\u7dda\uff0c\u5927\u91cf\u7684Client\u7aef\u7684\u8acb\u6c42\u4e0d\u50c5\u7121\u6cd5\u6d88\u5316\uff0cMySQL\u9019\u908a\u7684Connection\u6578\u76ee\u7adf\u7136\u6703\u5f88\u5feb\u5730\u66b4\u589e\uff0c\u9032\u800c\u8b93MySQL\u4e0d\u65b7\u5410Too many connections\u7684\u932f\u8aa4\u7684\u8a0a\u606f\u3002<\/p>\n<p><!--more--><\/p>\n<p>\u4f46\u662f\u5982\u679c\u53bbgoogle &#8220;ERROR 1040 (HY000): Too many connections&#8221; \u7684\u8a71\uff0c\u8a31\u591a\u6587\u7ae0\u6703\u8981\u4f60\u4fee\u6539max_connections\u7684\u6578\u76ee\u6216connection expire(\u903e\u671f)\u7684\u6642\u9593(\u4f8b\u5982<a href=\"http:\/\/www.dbafieldnotes.com\/2009\/01\/mysql-too-many-connections.html\" target=\"_blank\">\u9019\u7bc7<\/a>\uff0c\u4e0b\u9762\u7684\u6307\u4ee4\u5167\u5bb9\u4e5f\u90fd\u5f15\u7528\u81ea\u6b64\u7bc7\u6587\u7ae0)\u3002<\/p>\n<ul>\n<li>\u63d0\u9ad8<a href=\"http:\/\/dev.mysql.com\/doc\/refman\/5.0\/en\/server-system-variables.html#sysvar_max_connections\" target=\"_blank\">max_connection<\/a>\u7684\u6578\u503c\n<ul>\n<li>\u67e5\u8a62\u73fe\u5728\u7684max connections\u8a2d\u5b9a\uff0c\u4ee5\u5728\u4efb\u4f55\u53ef\u4ee5query\u7684\u5730\u65b9\u57f7\u884c\u4e0b\u9762\u7684\u6307\u4ee4\n<ul>\n<blockquote>\n<li>select VARIABLE_VALUE from information_schema.GLOBAL_VARIABLES where VARIABLE_NAME=&#8217;MAX_CONNECTIONS&#8217;;<\/li>\n<\/blockquote>\n<\/ul>\n<\/li>\n<li>\u67e5\u8a62\u73fe\u5728\u5df2\u7d93\u4f7f\u7528\u7684connections\u6578\u76ee\n<ul>\n<blockquote>\n<li>select count(*) from information_schema.PROCESSLIST;<\/li>\n<\/blockquote>\n<\/ul>\n<\/li>\n<li>\u670d\u52d9\u57f7\u884c\u4e2d\u52d5\u614b\u66f4\u6539max connections\uff0c\u53ef\u4ee5\u5728\u4efb\u4f55\u53ef\u4ee5query\u7684\u5730\u65b9\u57f7\u884c\u4e0b\u9762\u7684\u6307\u4ee4 (\u4e0b\u9762\u7684xxxx\u662f\u6578\u5b57\uff0c\u5373\u5141\u8a31\u7684\u6700\u5927\u7684connection\u6578\u76ee)\uff0c\u4e0d\u904e\u9019\u7a2e\u8a2d\u5b9a\u65b9\u5f0f\uff0cmysql\u670d\u52d9\u91cd\u555f\u5c31\u6703\u5931\u6548\u3002\n<ul>\n<blockquote>\n<li>set global max_connections = <strong><em>xxxx<\/em><\/strong>;<\/li>\n<\/blockquote>\n<\/ul>\n<\/li>\n<li>\u900f\u904e\u4fee\u6539\u8a2d\u5b9a\u6a94\u589e\u52a0max_connections (my.cnf \u6216\u662f my.ini)\uff0c\u5728 [mysqld] \u7684\u4e0b\u9762\u4fee\u6539 max_connections\u7684\u6578\u503c (\u5982\u679c\u6c92\u6709\u7684\u8a71\u8981\u81ea\u5df1\u52a0\u9032\u53bb\uff0c\u9810\u8a2d\u503c\u662f100)\uff0c\u4fee\u6539\u5f8c\u9700\u8981\u91cd\u555fmysql\u670d\u52d9\u624d\u6703\u751f\u6548<\/li>\n<\/ul>\n<\/li>\n<li>\u4fee\u6539connection\u7684\u903e\u671f\u6642\u9593(expire time)\uff0c\u8b93connection\u4e0d\u6703\u4f54\u7528\u904e\u4e45\u7684\u6642\u9593 <a href=\"http:\/\/dev.mysql.com\/doc\/refman\/5.0\/en\/server-system-variables.html#sysvar_interactive_timeout\" target=\"_blank\">interactive_timeout<\/a> (\u55ae\u4f4d\u662f\u79d2)\uff0c\u4e0b\u9762\u9019\u500b\u662f\u52d5\u614b\u4fee\u6539\u7684\u65b9\u6cd5\u3002\u975c\u614b\u4fee\u6539\u4e5f\u662f\u76f4\u63a5\u5728mysqld\u88e1\u9762\u52a0\u5165\u6216\u4fee\u6539interactive_timeout\u7684\u53c3\u6578\u5c31\u53ef\u4ee5\u4e86\u3002\n<ul>\n<li>set global interactive_timeout = 3600;<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\u4e0d\u904e\u5728\u9019\u500bcase\u88e1\u9762\u53bb\u4fee\u6539max_connections\u7684\u53c3\u6578\u662f\u6c92\u6709\u7528\u7684\uff0c\u56e0\u70baconnection\u589e\u52a0\u7684\u901f\u5ea6\u592a\u5feb\uff0c\u6700\u7d42\u6703\u704c\u7206MySQL\u7684 max_connection (\u6211\u66fe\u6709\u628amax_connections\u6539\u5230\u4e5d\u5341\u842c\uff0c\u4e0d\u904econnection\u70b8\u52303\u842c\u5de6\u53f3\u6b63\u500b\u7cfb\u7d71\u5c31\u7671\u7613\u4e86)\u3002<\/p>\n<p>\u56e0\u70ba\u539f\u672c\u7684\u7cfb\u7d71\u4e0d\u6703\u6709\u9019\u6a23\u7684\u554f\u984c\uff0c\u6240\u4ee5\u958b\u59cb\u63dbOS\u3001Switch Hub\u602a\u7f6a\u6240\u6709\u4fee\u6539\u904e\u7684\u6771\u897f\uff0c\u5f8c\u4f86trial and error\u537b\u767c\u73fe\uff0c\u5982\u679cAP\u6539\u7528<a href=\"\/wordpress\/index.php\/archives\/678\" target=\"_blank\">SSH Tunnel<\/a>\u4f86\u9023MySQL\u5c31\u4e0d\u6703\u6709\u76f8\u540c\u7684\u554f\u984c\uff0c\u9019\u5341\u5206\u602a\u7570\u3002\u5f8c\u4f86\u767e\u601d\u4e0d\u5f97\u5176\u89e3\u7684\u6642\u5019\u7a81\u7136\u5728\u67d0\u7bc7<a href=\"http:\/\/ubuntuforums.org\/showthread.php?t=862185 \" target=\"_blank\">\u8a0e\u8ad6\u4e32\u4e2d\u6709\u4eba\u63d0\u5230<\/a>\u53ef\u80fd\u7684\u539f\u56e0\u4e4b\u4e00\u662fMySQL\u8a66\u8457\u53bb\u53cd\u89e3AP\u7684\u4e3b\u6a5f\u540d\u7a31\uff0c\u800cDNS\u53c8\u6c92\u6709\u8a2d\u5b9aAP Server\u7684\u53cd\u89e3\u7684record\u624d\u6703\u51fa\u73fe\u9019\u500b\u554f\u984c\u3002\u6240\u4ee5\uff0c\u89e3\u6c7a\u7684\u65b9\u6cd5\u5982\u4e0b\uff1a<\/p>\n<ol>\n<li>\u53bbDNS\u628a\u6bcf\u53f0\u8981\u9023\u7684\u4e3b\u6a5f\u540d\u7a31\u8a2d\u53cd\u89e3<\/li>\n<li>\u8a2d\u5b9aMySQL Server\u7684\/etc\/hosts (\u5404\u7cfb\u7d71hosts\u653e\u7f6e\u4f4d\u7f6e\u8acb\u53c3\u8003<a href=\"http:\/\/en.wikipedia.org\/wiki\/Hosts_%28file%29\" target=\"_blank\">\u9019\u4e00\u7bc7<\/a>)\uff0c\u628a\u8981\u9023\u7684AP\u4e3b\u6a5f\u7684\u4e3b\u6a5f\u540d\u7a31\u8207IP\u8a2d\u5b9a\u4e0a\u53bb\u3002 (\u4f8b\u5982\uff1a\u4e0b\u9762\u9019\u6a23)\n<ul>\n<blockquote><p>192.168.100.101\u00a0\u00a0\u00a0\u00a0 ap-server1<br \/>\n192.168.100.102\u00a0\u00a0\u00a0\u00a0 ap-server2<\/p>\n<p>127.0.0.1 localhost mysql-serv<br \/>\n&#8230;.<\/p><\/blockquote>\n<\/ul>\n<\/li>\n<li>\u4fee\u6539MySQL\u7684\u8a2d\u5b9a\u6a94my.cnf (\u5728windows\u4e0a\u662fmy.ini)\uff0c\u5728[mysqld]\u4e0b\u9762\u591a\u52a0\u4e00\u884c <a href=\"http:\/\/dev.mysql.com\/doc\/refman\/5.0\/en\/server-options.html#option_mysqld_skip-name-resolve\" target=\"_blank\">skip-name-resolve<\/a> \u8b93mysql\u4e0d\u8981\u5728\u53bb\u53cd\u89e3\u4e3b\u6a5f\u540d\u7a31<\/li>\n<\/ol>\n<p>\u4fee\u6539\u4e86\u4e3b\u6a5f\u540d\u7a31\u53cd\u89e3\u7684\u554f\u984c\u5f8c\uff0cconnections\u5c31\u4e0d\u518d\u66b4\u589e\u4e86\uff0c\u63d0\u4f9b\u4e0a\u9762\u5e7e\u500b\u89e3\u6c7a\u65b9\u6cd5\uff0c\u8acb\u53c3\u8003\u5695\uff0c\u5e0c\u671b\u6709\u5e6b\u52a9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHP\u9023\u63a5\u9060\u7aefmysql server\u6700\u7d42\u9020\u6210ERROR 1040 (HY000): Too many connections \u6700\u8fd1\u9047\u5230\u4e00\u500b\u5f88\u8a6d\u7570\u7684\u554f\u984c\uff0c\u539f\u672c\u7684PHP\u7cfb\u7d71\u8981\u64f4\u589eAP Server\u4e26\u628aMySQL\u79fb\u5230\u4e00\u53f0\u7368\u7acb\u7684Server\u4e0a\u904b\u4f5c\uff0c\u539f\u672c\u8a8d\u70ba\u9019\u500btask\u5e7e\u4e4e\u662f\u6c92\u6709\u98a8\u96aa\u7684\uff0c\u6c92\u60f3\u5230\u4e00\u63a5\u4e0a\u7dda\uff0c\u5927\u91cf\u7684Client\u7aef\u7684\u8acb\u6c42\u4e0d\u50c5\u7121\u6cd5\u6d88\u5316\uff0cMySQL\u9019\u908a\u7684Connection\u6578\u76ee\u7adf\u7136\u6703\u5f88\u5feb\u5730\u66b4\u589e\uff0c\u9032\u800c\u8b93MySQL\u4e0d\u65b7\u5410Too many connections\u7684\u932f\u8aa4\u7684\u8a0a\u606f\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[15],"tags":[48,52,55,62],"_links":{"self":[{"href":"https:\/\/gwokae.mewggle.com\/wordpress\/wp-json\/wp\/v2\/posts\/683"}],"collection":[{"href":"https:\/\/gwokae.mewggle.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gwokae.mewggle.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gwokae.mewggle.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gwokae.mewggle.com\/wordpress\/wp-json\/wp\/v2\/comments?post=683"}],"version-history":[{"count":0,"href":"https:\/\/gwokae.mewggle.com\/wordpress\/wp-json\/wp\/v2\/posts\/683\/revisions"}],"wp:attachment":[{"href":"https:\/\/gwokae.mewggle.com\/wordpress\/wp-json\/wp\/v2\/media?parent=683"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gwokae.mewggle.com\/wordpress\/wp-json\/wp\/v2\/categories?post=683"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gwokae.mewggle.com\/wordpress\/wp-json\/wp\/v2\/tags?post=683"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}