\u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u4ecb\u7ecd\u4e86MySQL \u4e00\u5219\u6162\u65e5\u5fd7\u76d1\u63a7\u8bef\u62a5\u7684\u95ee\u9898\u5206\u6790\u4e0e\u89e3\u51b3\uff0c\u5e2e\u52a9\u5927\u5bb6\u66f4\u597d\u7684\u7406\u89e3\u548c\u4f7f\u7528MySQL\uff0c\u611f\u5174\u8da3\u7684\u670b\u53cb\u53ef\u4ee5\u4e86\u89e3\u4e0b<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n\u4e4b\u524d\u56e0\u4e3a\u5404\u79cd\u539f\u56e0\uff0c\u6709\u4e9b\u62a5\u8b66\u6ca1\u6709\u5f15\u8d77\u91cd\u89c6\uff0c\u6700\u8fd1\u653e\u5047\u9a6c\u4e0a\u6392\u9664\u4e86\u4e00\u4e9b\u6f5c\u5728\u7684\u4eba\u4e3a\u539f\u56e0\uff0c\u53d1\u73b0\u6570\u636e\u5e93\u7684\u6162\u65e5\u5fd7\u62a5\u8b66\u6709\u4e9b\u5947\u602a\uff0c\u4e3b\u8981\u8868\u73b0\u662f\u6162\u65e5\u5fd7\u62a5\u8b66\u4e0d\u5c5e\u5b9e\uff0c\u6536\u5230\u62a5\u8b66\u7684\u5373\u65f6\u901a\u4fe1\u63d0\u9192\u540e\uff0c\u9694\u4e00\u4f1a\u53bb\u6570\u636e\u5e93\u91cc\u9762\u53bb\u6392\u67e5\uff0c\u53d1\u73b0\u6162\u65e5\u5fd7\u7684\u6027\u80fd\u4f3c\u4e4e\u6ca1\u6709\u90a3\u4e48\u5dee\uff08\u6211\u8bbe\u7f6e\u7684\u4e00\u4e2a\u9608\u503c\u662f60\uff09\u3002<\/p>\n
\u6392\u67e5\u8fc7\u51e0\u6b21\u4ee3\u7801\u5c42\u9762\u7684\u903b\u8f91\uff0c\u6ca1\u6709\u53d1\u73b0\u660e\u663e\u7684\u95ee\u9898\uff0c\u51e0\u6b21\u4e0b\u6765\uff0c\u95ee\u9898\u4f9d\u65e7\uff0c\u8fd9\u53ef\u6fc0\u53d1\u4e86\u4fee\u6b63\u7684\u5ff5\u5934\uff0c\u51b3\u5b9a\u8ba4\u771f\u770b\u770b\u5230\u5e95\u662f\u4ec0\u4e48\u539f\u56e0\u3002\u540e\u7aef\u4f7f\u7528\u7684\u662f\u57fa\u4e8eORM\u7684\u6a21\u5f0f\uff0c\u6570\u636e\u90fd\u5b58\u50a8\u5728\u6a21\u578bMySQL_slowlog_sql_history\u5bf9\u5e94\u7684\u8868\u4e2d\u3002<\/p>\n
\u4ee3\u7801\u5c42\u9762\u662f\u7c7b\u4f3c\u5982\u4e0b\u7684\u903b\u8f91\uff1a<\/p>\n
MySQL_slowlog_sql_history.objects.filter(create_time__gt='2020-01-29 11:00:00',Query_time_pct_95__gt=60)<\/pre>\n\u4f20\u5165\u7684\u65f6\u95f4\u662f\u52a8\u6001\u7684\uff0c\u7136\u540e\u9608\u503c\u53d660\u79d2\uff0c\u6309\u7167\u9884\u671f\u5982\u679c\u62a5\u8b66\u51fa\u6765\u5c31\u80af\u5b9a\u662f\u6709\u95ee\u9898\u7684\u3002\u4e3a\u4e86\u8fdb\u4e00\u6b65\u9a8c\u8bc1\uff0c\u6211\u628a\u9608\u503c\u65f6\u95f4\u4fee\u6539\u4e3a600\uff0c\u7adf\u7136\u8fd8\u662f\u62a5\u51fa\u9519\u8bef\uff0c\u6267\u884c7~8\u79d2\u7684\u6162\u67e5\u8be2\u7167\u6837\u4f1a\u62a5\u51fa\u6765\u3002\u6211\u4f7f\u7528debug\u7684\u65b9\u5f0f\u5f97\u5230\u4e86ORM\u89e3\u6790\u5f97\u5230\u7684SQL:<\/p>\n
\r\nSELECT...`mysql_slowlog_sql_history`.`create_time`, `mysql_slowlog_sql_history`.`memo` \r\nFROM `mysql_slowlog_sql_history` \r\nWHERE (`mysql_slowlog_sql_history`.`create_time` > '2020-01-29 11:00:00' AND `mysql_slowlog_sql_history`.`Query_time_pct_95` > '600') LIMIT 21; \r\nargs=(u'2020-01-29 11:00:00', u'600')<\/pre>\n\u770bSQL\u6ca1\u95ee\u9898\u554a\u3002\u6211\u81ea\u5df1\u5728\u5ba2\u6237\u7aef\u6267\u884c\uff0c\u786e\u5b9e\u662f\u597d\u597d\u7684\uff0c\u53ea\u8fc7\u6ee4\u51fa\u4e86600\u79d2\u4ee5\u4e0a\u7684\u7ed3\u679c\u3002<\/p>\n
select ip_addr,db_port from mysql_slowlog_sql_history \r\nwhere create_time>'2020-01-29 00:00:00' and Query_time_pct_95 > 600;<\/pre>\n\u5bf9\u7740\u8fd9\u4e2a\u7ed3\u679c\u6211\u5f00\u59cb\u53cd\u601d\uff0c\u5230\u5e95\u662f\u4ec0\u4e48\u539f\u56e0\u5462\uff1f\u6211\u770b\u7740\u6a21\u578b\u7684\u5b57\u6bb5\u5b9a\u4e49\u5f00\u59cb\u6709\u6240\u609f\uff0c\u7136\u540e\u5feb\u901f\u9a8c\u8bc1\u4e86\u4e00\u756a\u3002\u4e3a\u4e86\u65b9\u4fbf\u8bf4\u660e\uff0c\u6211\u521b\u5efa\u4e86\u4e00\u4e2a\u6d4b\u8bd5\u8868test_dummy.<\/p>\n
\r\ncreate table test_dummy(id int primary key auto_increment,Query_time_pct_95 varchar(100));<\/pre>\n\u521d\u59cb\u5316\u51e0\u6761\u6570\u636e\u3002<\/p>\n
insert into test_dummy(Query_time_pct_95 ) values('8.83736'),('7.70056'),('5.09871'),('4.32582');\r\n+----+-------------------+\r\n| id | Query_time_pct_95 |\r\n+----+-------------------+\r\n| 1 | 8.83736 |\r\n| 4 | 7.70056 |\r\n| 7 | 5.09871 |\r\n| 10 | 4.32582 |\r\n+----+-------------------+\r\n4 rows in set (0.00 sec)<\/pre>\n\u7136\u540e\u4f7f\u7528\u5982\u4e0b\u7684\u4e24\u6761\u8bed\u53e5\u6765\u8fdb\u884c\u5bf9\u6bd4\u6d4b\u8bd5\u3002<\/p>\n
\r\nmysql> select *from test_dummy where Query_time_pct_95>600;\r\nEmpty set (0.00 sec)<\/pre>\n\r\nmysql> select *from test_dummy where Query_time_pct_95>'600';\r\n+----+-------------------+\r\n| id | Query_time_pct_95 |\r\n+----+-------------------+\r\n| 1 | 8.837364 |\r\n| 2 | 7.700558 |\r\n+----+-------------------+\r\n2 rows in set (0.00 sec)<\/pre>\n\u53ef\u4ee5\u770b\u5230\uff0c\u4f7f\u7528\u4e86\u6574\u578b\u6570\u503c\u7684\u65f6\u5019\uff0c\u6ca1\u6709\u8fd4\u56de\u7ed3\u679c\uff0c\u800c\u4f7f\u7528\u4e86\u5b57\u7b26\u7c7b\u578b\u7684\u65f6\u5019\uff0c\u5339\u914d\u7684\u7ed3\u679c\u662f\u6309\u7167\u6700\u5de6\u5339\u914d\u7684\u6a21\u5f0f\u6765\u8fdb\u884c\u8fc7\u6ee4\u7684\uff0c\u4e5f\u5c31\u610f\u5473\u7740\u5728\u6570\u636e\u5e93\u5c42\u9762\u5bf9\u4e8e\u6d6e\u70b9\u6570\u7684\u5904\u7406\u8fd8\u662f\u5dee\u522b\u5f88\u5927\u7684\u3002\u6240\u4ee5\u8fd9\u4e2a\u95ee\u9898\u7684\u5feb\u901f\u4fee\u590d\u65b9\u5f0f\u5c31\u662f\u5728\u6570\u636e\u5e93\u5c42\u9762\u4fee\u6539\u6570\u636e\u8868\u7684\u7c7b\u578b\u4e3afloat,\u800c\u5728\u7cbe\u5ea6\u635f\u5931\u65b9\u9762\u8fd9\u5757\u7684\u5f71\u54cd\u662f\u53ef\u4ee5\u5ffd\u7565\u4e0d\u8ba1\u7684\u3002\u518d\u6b21\u9a8c\u8bc1\uff0c\u8fd9\u4e2a\u95ee\u9898\u5c31\u6ca1\u6709\u518d\u6b21\u51fa\u73b0\u3002<\/p>\n
\u4ee5\u4e0a\u5c31\u662fMySQL \u4e00\u5219\u6162\u65e5\u5fd7\u76d1\u63a7\u8bef\u62a5\u7684\u95ee\u9898\u5206\u6790\u4e0e\u89e3\u51b3\u7684\u8be6\u7ec6\u5185\u5bb9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"
\u4e4b\u524d\u56e0\u4e3a\u5404\u79cd\u539f\u56e0\uff0c\u6709\u4e9b\u62a5\u8b66\u6ca1\u6709\u5f15\u8d77\u91cd\u89c6\uff0c\u6700\u8fd1\u653e\u5047\u9a6c\u4e0a\u6392\u9664\u4e86\u4e00\u4e9b\u6f5c\u5728\u7684\u4eba\u4e3a\u539f\u56e0\uff0c\u53d1\u73b0\u6570\u636e\u5e93\u7684\u6162\u65e5\u5fd7\u62a5\u8b66\u6709\u4e9b\u5947\u602a\uff0c […]<\/p>\n","protected":false},"author":1482,"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-210619","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\/210619","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\/1482"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=210619"}],"version-history":[{"count":3,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/210619\/revisions"}],"predecessor-version":[{"id":210622,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/210619\/revisions\/210622"}],"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=210619"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=210619"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=210619"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}