{"id":5350,"date":"2020-07-29T21:27:00","date_gmt":"2020-07-29T13:27:00","guid":{"rendered":"http:\/\/39.97.231.10\/?p=5350"},"modified":"2020-07-29T21:27:00","modified_gmt":"2020-07-29T13:27:00","slug":"mysql-sql%e6%80%a7%e8%83%bd%e5%88%86%e6%9e%90-show-profile","status":"publish","type":"post","link":"http:\/\/www.weijing.co\/?p=5350","title":{"rendered":"MySQL SQL\u6027\u80fd\u5206\u6790 show profile"},"content":{"rendered":"<div class=\\\"blog_content\\\">\n<div class=\\\"blog_detail\\\">\n<div>\nMySQL show profile \u548c show profiles \u547d\u4ee4\u7528\u4e8e\u5c55\u793aSQL\u8bed\u53e5\u6267\u884c\u8fc7\u7a0b\u4e2d\u7684\u8d44\u6e90\u4f7f\u7528\u60c5\u51b5\uff0c\u5305\u62ecCPU\u7684\u4f7f\u7528\uff0cCPU\u4e0a\u4e0b\u6587\u5207\u6362\uff0cIO\u7b49\u5f85\uff0c\u5185\u5b58\u4f7f\u7528\u7b49\uff0c\u8fd9\u4e2a\u547d\u4ee4\u5bf9\u4e8e\u5206\u6790\u67d0\u4e2aSQL\u7684\u6027\u80fd\u74f6\u9888\u975e\u5e38\u6709\u5e2e\u52a9\uff0c\u501f\u52a9\u4e8eshow profile\u7684\u8f93\u51fa\u4fe1\u606f\uff0c\u80fd\u8ba9\u6211\u4eec\u77e5\u9053\u4e00\u4e2aSQL\u5728\u54ea\u4e2a\u9636\u6bb5\u8017\u65f6\u6700\u957f\uff0c\u6d88\u8017\u8d44\u6e90\u6700\u591a\uff0c\u4ece\u800c\u4e3aSQL\u4f18\u5316\uff0c\u63d0\u9ad8SQL\u6027\u80fd\u63d0\u4f9b\u91cd\u8981\u7684\u4f9d\u636e\u3002<\/p>\n<h5>1. show profile\u8bed\u6cd5<\/h5>\n<p>SHOW PROFILE [type [, type] &#8230; ] [FOR QUERY n] [LIMIT row_count [OFFSET offset]]<br \/>\ntype: { ALL | BLOCK IO | CONTEXT SWITCHES | CPU | IPC | MEMORY | PAGE FAULTS | SOURCE | SWAPS }<\/p>\n<h5>2. \u542f\u7528profiling:<\/h5>\n<p>\u4f7f\u7528show profile\u547d\u4ee4\u4e4b\u524d\uff0c\u5148\u542f\u7528profiling\uff0c profiling\u662fsession\u7ea7\u53d8\u91cf\uff0csession\u5173\u95ed\uff0c\u8be5session\u7684profiling\u4fe1\u606f\u4e5f\u4f1a\u4e22\u5931\u3002<\/p>\n<pre><code>mysql&gt; set profiling = 1;\n<\/code><\/pre>\n<h5>3. show profiles<\/h5>\n<p>\u5f00\u542fprofiling\u4e4b\u540e\uff0c\u6267\u884c\u51e0\u6761SQL\uff0c\u7136\u540e\u6267\u884c show profiles \u5c55\u793a\u6700\u8fd1\u6267\u884c\u7684\u51e0\u4e2aSQL\u7684\u6267\u884c\u8017\u65f6\u60c5\u51b5\uff0c\u5177\u4f53\u80fd\u6536\u96c6\u591a\u5c11\u4e2aSQL\uff0c\u7531\u53c2\u6570 profiling_history_size\u51b3\u5b9a\uff0c\u9ed8\u8ba4\u503c\u4e3a15\uff0c\u6700\u5927\u503c\u4e3a100\u3002\u5982\u679c\u8bbe\u7f6e\u4e3a0\uff0c\u7b49\u540c\u4e8e\u5173\u95edprofiling\u3002show profiles\u5c55\u793a\u7684\u662f\u7b80\u8981\u7684\u8017\u65f6\u4fe1\u606f\uff0c\u5982\u679c\u60f3\u4e86\u89e3\u67d0\u4e2aSQL\u7684\u5177\u4f53\u8017\u65f6\u60c5\u51b5\uff0c\u6267\u884cshow profile \u67e5\u770b\u3002<\/p>\n<pre><code>mysql&gt; show profiles;\n+----------+------------+------------------------------+\n| Query_ID | Duration\u00a0\u00a0 | Query\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 |\n+----------+------------+------------------------------+\n|\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 1 | 0.00248450 | select * from blog.blog\u00a0\u00a0\u00a0\u00a0\u00a0 |\n|\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 2 | 0.00071050 | select * from blog.blog_type |\n+----------+------------+------------------------------+\n2 rows in set, 1 warning (0.00 sec)\n<\/code><\/pre>\n<h5>4. show profile for query n<\/h5>\n<p>show profile \u5c55\u793a\u4e00\u4e2aSQL\u8bed\u53e5\u7684\u6267\u884c\u8017\u65f6\u7ec6\u8282\uff0c\u5982\u679c\u4e0d\u52a0 for query {n} \u5b50\u53e5\uff0c\u9ed8\u8ba4\u5c55\u793a\u6700\u65b0\u7684\u4e00\u6b21SQL\u7684\u6267\u884c\u60c5\u51b5\uff0c\u52a0\u4e86for query {n}\uff0c\u8868\u793a\u5c55\u793a\u7b2cn\u4e2a SQL\u7684\u6267\u884c\u60c5\u51b5\u3002\u6bd4\u5982\u770b\u7b2c1\u4e2aSQL\uff0c\u6267\u884cshow profile for query 1;<\/p>\n<pre><code>mysql&gt; show profile for query 1;\n+----------------------+----------+\n| Status               | Duration |\n+----------------------+----------+\n| starting             | 0.000117 |\n| checking permissions | 0.000015 |\n| Opening tables       | 0.000033 |\n| init                 | 0.000054 |\n| System lock          | 0.000020 |\n| optimizing           | 0.000006 |\n| statistics           | 0.000021 |\n| preparing            | 0.000017 |\n| executing            | 0.000003 |\n| Sending data         | 0.002045 |\n| end                  | 0.000010 |\n| query end            | 0.000060 |\n| closing tables       | 0.000020 |\n| freeing items        | 0.000047 |\n| cleaning up          | 0.000019 |\n+----------------------+----------+\n15 rows in set, 1 warning (0.00 sec)\n<\/code><\/pre>\n<p>\u5728\u6267\u884cshow profile\u65f6\uff0c\u53ef\u4ee5\u52a0\u4e0a\u7c7b\u578b\u5b50\u53e5\uff0c\u6bd4\u5982CPU,IPC\u7b49\uff0c\u67e5\u770b\u5177\u4f53\u67d0\u7c7b\u8d44\u6e90\u7684\u6d88\u8017\u60c5\u51b5\uff0c\u4f8b\u5982\uff1a<br \/>\nshow profile cpu,ipc for query 1;<br \/>\nshow profile \u548c show profiles \u9664\u4e86\u8fd9\u4e24\u4e2a\u8bed\u53e5\u4e4b\u5916\uff0c\u53ef\u4ee5\u5c55\u793a\u6240\u6709\u7684SQL\u8bed\u53e5\u7684\u6267\u884c\u60c5\u51b5\uff0c\u5305\u62ec\u6709\u8bed\u6cd5\u9519\u8bef\u7684SQL\u4e5f\u4f1a\u88ab\u76d1\u6d4b\u5230\u3002\u6bd4\u5982\u4e0b\u9762Query_ID \u4e3a4\u7684\u8fd9\u4e2aSQL\uff0c\u6709\u8bed\u6cd5\u9519\u8bef\uff0c\u4f46\u4ecd\u7136\u88ab\u8bb0\u5f55\u5230\u4e86show profiles;\u5217\u8868\u4e2d\u3002<\/p>\n<pre><code>mysql&gt; show profiles;\n+----------+------------+------------------------------+\n| Query_ID | Duration   | Query                        |\n+----------+------------+------------------------------+\n|        1 | 0.00248450 | select * from blog.blog      |\n|        2 | 0.00071050 | select * from blog.blog_type |\n|        3 | 0.00012125 | show profile for 1           |\n|        4 | 0.00011900 | select from blog.blog        |\n+----------+------------+------------------------------+\n4 rows in set, 1 warning (0.00 sec)\n<\/code><\/pre>\n<h5>5. show profile \u5c06\u88ab\u5e9f\u5f03<\/h5>\n<p>\u5728MySQL 5.7\uff0c 8.0\u7248\u672c\u91cc\u6267\u884cshow profile\u547d\u4ee4\uff0c\u4f1a\u6709\u4e00\u4e2awarning\u4fe1\u606f\uff0c\u63d0\u793a\u5982\u4e0b\uff1a<\/p>\n<pre><code>\\'SHOW PROFILES\\' is deprecated and will be removed in a future release. Please use Performance Schema instead\n<\/code><\/pre>\n<p>show profile \u547d\u4ee4\u5c06\u4f1a\u88ab\u5e9f\u5f03\uff0c\u53d6\u800c\u4ee3\u4e4b\u7684\u662f\u4f7f\u7528Performance Schema\u3002\n<\/p><\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>MySQL show profile \u548c show profiles \u547d\u4ee4\u7528\u4e8e\u5c55\u793aSQL\u8bed\u53e5\u6267\u884c\u8fc7\u7a0b\u4e2d\u7684\u8d44\u6e90\u4f7f &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"\" href=\"http:\/\/www.weijing.co\/?p=5350\"> <span class=\"screen-reader-text\">MySQL SQL\u6027\u80fd\u5206\u6790 show profile<\/span> \u67e5\u770b\u5168\u6587 &raquo;<\/a><\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"default","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"default","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":""},"categories":[90,88],"tags":[],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false,"mailpoet_newsletter_max":false,"woocommerce_thumbnail":false,"woocommerce_single":false,"woocommerce_gallery_thumbnail":false,"shop_catalog":false,"shop_single":false,"shop_thumbnail":false},"uagb_author_info":{"display_name":"weijing","author_link":"http:\/\/www.weijing.co\/?author=4"},"uagb_comment_info":0,"uagb_excerpt":"MySQL show profile \u548c show profiles \u547d\u4ee4\u7528\u4e8e\u5c55\u793aSQL\u8bed\u53e5\u6267\u884c\u8fc7\u7a0b\u4e2d\u7684\u8d44\u6e90\u4f7f&hellip;","_links":{"self":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/posts\/5350"}],"collection":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5350"}],"version-history":[{"count":0,"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/posts\/5350\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5350"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5350"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5350"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}