{"id":166865,"date":"2019-12-29T09:20:25","date_gmt":"2019-12-29T01:20:25","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=166865"},"modified":"2019-12-17T16:20:39","modified_gmt":"2019-12-17T08:20:39","slug":"high-mysql-load","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/high-mysql-load.html","title":{"rendered":"\u5982\u4f55\u89e3\u51b3\u7f51\u7ad9\u8bbf\u95ee\u6162-MySQL\u8d1f\u8f7d\u9ad8"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\nMySQL\u662f\u4e00\u4e2a\u5173\u7cfb\u578b\u6570\u636e\u5e93\u7ba1\u7406\u7cfb\u7edf\uff0c\u7531\u745e\u5178MySQL AB \u516c\u53f8\u5f00\u53d1\uff0c\u5c5e\u4e8e Oracle \u65d7\u4e0b\u4ea7\u54c1\u3002MySQL \u662f\u6700\u6d41\u884c\u7684\u5173\u7cfb\u578b\u6570\u636e\u5e93\u7ba1\u7406\u7cfb\u7edf\u4e4b\u4e00\uff0c\u5728 WEB \u5e94\u7528\u65b9\u9762\uff0cMySQL\u662f\u6700\u597d\u7684 RDBMS (Relational Database Management System\uff0c\u5173\u7cfb\u6570\u636e\u5e93\u7ba1\u7406\u7cfb\u7edf) \u5e94\u7528\u8f6f\u4ef6\u4e4b\u4e00\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n
\u6545\u969c\u5206\u6790<\/strong><\/div>\n

\u9996\u5148\uff0c\u5224\u65ad\u8bbf\u95ee\u6162\u73b0\u8c61\uff0c\u662f\u4e2a\u4eba\u8fd8\u662f\u96c6\u4f53\uff1f\uff1f\uff1f<\/p>\n

\"\u4e2a\u4eba\"\u73b0\u8c61\u6392\u67e5\uff1a\u68c0\u67e5\u4e2a\u4eba\u7f51\u7edc\uff0cpc\uff0c\u6d4f\u89c8\u5668\u3001\u4e2d\u6bd2\u7b49\uff0c\u65e0\u9700\u591a\u8bf4\u81ea\u5df1\u767e\u5ea6\uff1b<\/p>\n

\"\u96c6\u4f53\"\u73b0\u8c61\u6392\u67e5\uff1a\u68c0\u67e5\u6838\u5fc3\u8def\u7531\u4ea4\u6362\uff0cISP\u8fd0\u884c\u5546\u7f51\u7edc\uff0cARP***\uff0cDNS\u670d\u52a1\uff0c\u5404\u670d\u52a1\u5668\u72b6\u6001\uff1b<\/p>\n

\u670d\u52a1\u72b6\u6001\u6392\u67e5\uff1azabbix\u76d1\u63a7\uff1b\u521b\u5efa\u6d4b\u8bd5\u9875\u9762\u6d4b\u8bd5: \u9759\u6001\u9875\u9762=\u300b\u52a8\u6001\u9875\u9762=\u300b\u52a8\u6001\u4ea4\u4e92\u9875\u9762<\/p>\n

\u901a\u8fc7\u4e0a\u8ff0\u6392\u67e5\uff0c\u5f53\u6d4b\u8bd5php\u4e0emysql\u52a8\u6001\u4ea4\u4e92\u9875\u9762\u5f88\u6162\uff0c\u6240\u4ee5\u786e\u5b9a\u4e3amysql\u670d\u52a1\u5668\u5f02\u5e38\uff0c\u7acb\u523b\u767b\u5f55mysql\uff0c\u901a\u8fc7top\u547d\u4ee4 \u67e5\u770b\u670d\u52a1\u5668\u8d1f\u8f7d,\u53d1\u73b0 mysql\u7adf\u7136\u767e\u5206\u4e4b\u4e24\u767e\u7684cpu,\u5f15\u8d77Mysql \u8d1f\u8f7d\u8fd9\u4e48\u9ad8\u7684\u539f\u56e0,\u4f30\u8ba1\u662f\u6709SQL\u6162\u67e5\u8be2\u8bed\u53e5\u6216\u78c1\u76d8I\/O\u95ee\u9898\uff1b<\/p>\n

MySQL\u8d1f\u8f7d\u9ad8\u6392\u67e5\u601d\u8def<\/strong><\/div>\n

\u786e\u5b9a\u9ad8\u8d1f\u8f7d\u7684\u7c7b\u578b,top\u547d\u4ee4\u770b\u8d1f\u8f7d\u9ad8\u662fCPU\u8fd8\u662f\u78c1\u76d8I\/O\u3002<\/p>\n

mysql \u4e0b\u67e5\u770b\u5f53\u524d\u7684\u8fde\u63a5\u6570\u4e0e\u6267\u884c\u7684sql \u8bed\u53e5\u3002<\/p>\n

\u68c0\u67e5\u6162\u67e5\u8be2\u65e5\u5fd7\uff0c\u53ef\u80fd\u662f\u6162\u67e5\u8be2\u5f15\u8d77\u8d1f\u8f7d\u9ad8\u3002<\/p>\n

\u68c0\u67e5\u786c\u4ef6\u95ee\u9898\uff0c\u662f\u5426\u78c1\u76d8\u6545\u969c\u95ee\u9898\u9020\u6210\u7684\u3002<\/p>\n

\u68c0\u67e5\u76d1\u63a7\u5e73\u53f0\uff0c\u5bf9\u6bd4\u6b64\u673a\u5668\u4e0d\u540c\u65f6\u95f4\u7684\u8d1f\u8f7d\u3002<\/p>\n

\u786e\u5b9a\u8d1f\u8f7d\u7c7b\u578b(top)<\/strong><\/span><\/div>\n
\r\ntop - 10:14:18 up 23 days, 11:01,  1 user, load average: 124.17, 55.88, 24.70 \r\nTasks: 138 total,   1 running, 137 sleeping,   0 stopped,   0 zombie \r\nCpu(s):  2.4%us,  1.0%sy,  0.0%ni, 95.2%id,  2.0%wa,  0.1%hi,  0.2%si,  0.0%st \r\nMem:   3090528k total,  2965772k used,   124756k free,    93332k buffers \r\nSwap:  4192956k total,  2425132k used,  1767824k free,   756524k cached \r\nPID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND \r\n30833 mysql     15   0 6250m 2.5g 4076 S 257.1 49.9 529:34.45 mysqld\r\n<\/pre>\n
\u67e5\u770b\u5f53\u524dMySQL\u7684\u8fde\u63a5\u6570\u4e0e\u6267\u884c\u7684sql\u8bed\u53e5<\/strong><\/span><\/div>\n

\u65e0\u9700\u767b\u9646\uff0c\u975e\u4ea4\u4e92\u67e5\u8be2\uff0c\u53ef\u4ee5grep\u8fc7\u6ee4\uff0c\u66f4\u76f4\u89c2\u770b\u7ed3\u679c<\/p>\n

\r\nmysql -uroot -pqiuyuetao -S  \/data\/3306\/mysql.sock -e \"show full processlist;\" |egrep -vi \"sleep\"\r\n<\/pre>\n
\u767b\u9646myslq\u67e5\u770b<\/strong><\/span><\/div>\n
\r\nshow full processlist;\r\n    Id  User    Host    db  Command Time    State   Info \r\n    192 slave   8.8.8.142:39820 NULL    Binlog Dump 58982   Has sent all binlog to slave; waiting for binlog to be updated  NULL \r\n    194 slave   8.8.8.120:41075 NULL    Binlog Dump 58982   Has sent all binlog to slave; waiting for binlog to be updated  NULL \r\n    424891 biotherm    8.8.8.46:57861  biotherm    Query   493 Sending data    SELECT * FROM xxx_list WHERE tid = '1112'  AND del = 0  ORDER BY  id \r\n    DESC  LIMIT 0, 4 \r\n    424917 biotherm    8.8.8.49:50984  biotherm    Query   488 Sending data    SELECT * FROM xxx_list WHERE tid = '1112'  AND del = 0  ORDER BY  id \r\n    DESC  LIMIT 0, 4 \r\n    .............................................. \r\n    430330 biotherm    8.8.8.42:35982  biotherm    Query   487 Sending data    SELECT * FROM xxx_list WHERE tid = '1112'  AND del = 0\r\n<\/pre>\n
\u8bb0\u5f55SQL\u6162\u67e5\u8be2<\/strong><\/span><\/div>\n

\u7f16\u8f91Mysql \u914d\u7f6e\u6587\u4ef6(my.cnf),\u5728[mysqld]\u5b57\u6bb5\u6dfb\u52a0\u4ee5\u4e0b\u51e0\u884c:<\/p>\n

\r\nlog_slow_queries = \/data\/3306\/slow_queries.log               #\u6162\u67e5\u8be2\u65e5\u5fd7\u8def\u5f84 \r\nlong_query_time = 2                                       #\u8bb0\u5f55SQL\u67e5\u8be2\u8d85\u8fc72s\u7684\u8bed\u53e5 \r\nlog-queries-not-using-indexes = 1                          #\u8bb0\u5f55\u6ca1\u6709\u4f7f\u7528\u7d22\u5f15\u7684sql\r\n<\/pre>\n
\u67e5\u770b\u6162\u67e5\u8be2\u65e5\u5fd7<\/strong><\/span><\/div>\n
\r\ntail \/data\/3306\/slow_queries.log \r\n# Time: 130305  9:48:13 \r\n# User@Host: biotherm[biotherm] @  [8.8.8.45] \r\n# Query_time: 1294.881407  Lock_time: 0.000179 Rows_sent: 4  Rows_examined: 1318033 \r\nSET timestamp=1363916893; \r\nSELECT * FROM xxx_list WHERE tid = '11xx'  AND del = 0  ORDER BY  id DESC  LIMIT 0, 4;\r\n<\/pre>\n
\u65e5\u5fd7\u53c2\u6570\u8bf4\u660e<\/strong><\/span><\/div>\n
\r\nQuery_time: 0 Lock_time: 0 Rows_sent: 1 Rows_examined: 54\r\n#\u67e5\u8be2\u65f6\u95f4        \u9501\u5b9a\u65f6\u95f4       \u67e5\u8be2\u7ed3\u679c\u884c\u6570      \u626b\u63cf\u884c\u6570\r\n##\u4e3b\u8981\u770b\u626b\u63cf\u884c\u6570\u591a\u7684\u8bed\u53e5,\u7136\u540e\u53bb\u6570\u636e\u5e93\u52a0\u4e0a\u5bf9\u5e94\u7684\u7d22\u5f15,\u518d\u4f18\u5316\u4e0b\u53d8\u6001\u7684sql \u8bed\u53e5\u3002\r\n<\/pre>\n
\u5176\u5b83\u65b9\u6cd5<\/strong><\/div>\n

PHP\u7a0b\u5e8f\u4e2d\uff0c\u4e0d\u4f7f\u7528\u6301\u4e45\u8fde\u63a5\uff0c\u5373\u4f7f\u7528mysql_connetct \u800c\u4e0d\u662fpconnect\uff08JAVA\u8c03\u6574\u8fde\u63a5\u6c60\uff09<\/p>\n

PHP\u7a0b\u5e8f\u6267\u884c\u5b8c\uff0c\u5e94\u8be5\u663e\u793a\u8c03\u7528mysql_colse ##\u5f88\u591a\u5f00\u53d1\u53ea\u6709open \u6ca1\u6709colse<\/p>\n

SQL\u6162\u67e5\u8be2\u8bed\u53e5\u4f18\u5316<\/p>\n

\u6781\u7aef\u60c5\u51b5kill sql\u8fdb\u7a0b<\/strong><\/div>\n

\u627e\u51fa\u5360\u7528cpu\u65f6\u95f4\u8fc7\u957f\u7684sql\uff0c\u5728mysql \u4e0b\u6267\u884c\u5982\u4e0b\u547d\u4ee4\uff1a<\/p>\n

\r\nshow full processlist;\r\n<\/pre>\n

\u786e\u5b9a\u540e\u4e00\u6761sql\u5904\u4e8eQuery\u72b6\u6001\uff0c\u4e14Time\u65f6\u95f4\u8fc7\u957f\uff0c\u9501\u5b9a\u5b83\u7684ID\uff0c\u6267\u884c\u5982\u4e0b\u547d\u4ee4\uff1a<\/p>\n

\r\nkill QUERY  269815764;\r\n<\/pre>\n

\u6ce8\u610f\uff1a\u6740\u6b7b sql\u8fdb\u7a0b\uff0c\u53ef\u80fd\u5bfc\u81f4\u6570\u636e\u4e22\u5931\uff0c\u6240\u4ee5\u6267\u884c\u524d\u8981\u8861\u91cf\u6570\u636e\u7684\u91cd\u8981\u6027\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

\u9996\u5148\uff0c\u5224\u65ad\u8bbf\u95ee\u6162\u73b0\u8c61\uff0c\u662f\u4e2a\u4eba\u8fd8\u662f\u96c6\u4f53\uff1f\uff1f\uff1f “\u4e2a\u4eba”\u73b0\u8c61\u6392\u67e5\uff1a\u68c0\u67e5\u4e2a\u4eba\u7f51\u7edc\uff0cpc\uff0c\u6d4f\u89c8\u5668\u3001\u4e2d\u6bd2\u7b49\uff0c\u65e0\u9700\u591a\u8bf4\u81ea\u5df1 […]<\/p>\n","protected":false},"author":1479,"featured_media":4956,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-166865","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/166865","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1479"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=166865"}],"version-history":[{"count":5,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/166865\/revisions"}],"predecessor-version":[{"id":167184,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/166865\/revisions\/167184"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/4956"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=166865"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=166865"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=166865"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}