{"id":1240,"date":"2025-07-30T04:26:34","date_gmt":"2025-07-29T20:26:34","guid":{"rendered":"https:\/\/www.hgfwq.com\/blog\/?p=1240"},"modified":"2025-07-30T04:26:34","modified_gmt":"2025-07-29T20:26:34","slug":"druid%e5%bc%80%e5%90%afsql%e6%97%a5%e5%bf%97%e6%89%93%e5%8d%b0%e7%9a%84%e9%87%8d%e8%a6%81%e6%80%a7%e4%b8%8e%e9%85%8d%e7%bd%ae%e8%af%a6%e8%a7%a3","status":"publish","type":"post","link":"https:\/\/www.hgfwq.com\/blog\/1240.html","title":{"rendered":"druid\u5f00\u542fsql\u65e5\u5fd7\u6253\u5370\u7684\u91cd\u8981\u6027\u4e0e\u914d\u7f6e\u8be6\u89e3"},"content":{"rendered":"<p><h3>druid\u5f00\u542fsql\u65e5\u5fd7\u6253\u5370\u5185\u5bb9\u5305\u542b\u54ea\u4e9b\uff1f<\/h3>\n<\/p>\n<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/www.hgfwq.com\/blog\/wp-content\/uploads\/2025\/07\/ej13p.jpg\" alt=\"druid\u5f00\u542fsql\u65e5\u5fd7\u6253\u5370\u7684\u91cd\u8981\u6027\u4e0e\u914d\u7f6e\u8be6\u89e3\" title=\"druid\u5f00\u542fsql\u65e5\u5fd7\u6253\u5370\u7684\u91cd\u8981\u6027\u4e0e\u914d\u7f6e\u8be6\u89e3\"><\/p>\n<p><p>druid\u5f00\u542fsql\u65e5\u5fd7\u6253\u5370\u540e\uff0c\u53ef\u4ee5\u8bb0\u5f55\u67e5\u8be2\u8bed\u53e5\u3001\u6267\u884c\u65f6\u95f4\u3001SQL\u6267\u884c\u7ed3\u679c\u7b49\u4fe1\u606f\u3002\u5177\u4f53\u5305\u542b\u4ee5\u4e0b\u5185\u5bb9\uff1a<\/p>\n<\/p>\n<ul>\n<li>SQL\u8bed\u53e5\uff1a\u663e\u793a\u6267\u884c\u7684SQL\u8bed\u53e5\u3002<\/li>\n<li>\u6267\u884c\u65f6\u95f4\uff1a\u8bb0\u5f55SQL\u8bed\u53e5\u7684\u6267\u884c\u65f6\u95f4\u3002<\/li>\n<li>SQL\u6267\u884c\u7ed3\u679c\uff1a\u663e\u793aSQL\u8bed\u53e5\u7684\u6267\u884c\u7ed3\u679c\u3002<\/li>\n<li>\u53c2\u6570\u503c\uff1a\u8bb0\u5f55SQL\u8bed\u53e5\u4e2d\u7684\u53c2\u6570\u503c\u3002<\/li>\n<li>\u5f02\u5e38\u4fe1\u606f\uff1a\u5982\u679cSQL\u6267\u884c\u8fc7\u7a0b\u4e2d\u51fa\u73b0\u5f02\u5e38\uff0c\u4e5f\u4f1a\u8bb0\u5f55\u76f8\u5173\u5f02\u5e38\u4fe1\u606f\u3002<\/li>\n<\/ul>\n<p><h3>druid\u4e2d\u54ea\u4e2a\u914d\u7f6e\u9879\u63a7\u5236sql\u65e5\u5fd7\u6253\u5370\uff1f<\/h3>\n<\/p>\n<p><p>druid\u4e2d\u63a7\u5236sql\u65e5\u5fd7\u6253\u5370\u7684\u914d\u7f6e\u9879\u662f<code>sqlLogEnable<\/code>\u3002\u5f53\u5c06\u6b64\u914d\u7f6e\u9879\u8bbe\u7f6e\u4e3atrue\u65f6\uff0cdruid\u4f1a\u5f00\u542fsql\u65e5\u5fd7\u6253\u5370\u529f\u80fd\u3002<\/p>\n<\/p>\n<p><h3>\u5982\u4f55\u5f00\u542fdruid\u7684sql\u65e5\u5fd7\u6253\u5370\u529f\u80fd\uff1f<\/h3>\n<\/p>\n<p><p>\u5f00\u542fdruid\u7684sql\u65e5\u5fd7\u6253\u5370\u529f\u80fd\u975e\u5e38\u7b80\u5355\uff0c\u53ea\u9700\u5728druid\u7684\u914d\u7f6e\u6587\u4ef6\u4e2d\u6dfb\u52a0\u6216\u4fee\u6539\u4ee5\u4e0b\u914d\u7f6e\u9879\uff1a<\/p>\n<\/p>\n<p><pre><code>sqlLogEnable=true<\/p>\r\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5982\u679c\u4f60\u4f7f\u7528\u7684\u662fdruid\u7684XML\u914d\u7f6e\u65b9\u5f0f\uff0c\u53ef\u4ee5\u5728<code>filters<\/code>\u6807\u7b7e\u4e0b\u6dfb\u52a0\u4ee5\u4e0b\u914d\u7f6e\uff1a<\/p>\n<\/p>\n<p><pre><code>&lt;filter name=\"stat\" class=\"com.alibaba.druid.filter.stat.StatFilter\"&gt;<\/p>\r\n<p>  &lt;property name=\"logSlowSql\" value=\"true\" \/&gt;<\/p>\r\n<p>  &lt;property name=\"slowSqlMillis\" value=\"1000\" \/&gt;<\/p>\r\n<p>  &lt;property name=\"log4j2\" value=\"true\" \/&gt;<\/p>\r\n<p>  &lt;property name=\"logError\" value=\"true\" \/&gt;<\/p>\r\n<p>&lt;\/filter&gt;<\/p>\r\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u63a8\u8350\u4f7f\u7528\u54ea\u4e9b\u65e5\u5fd7\u6846\u67b6\u6765\u8bb0\u5f55druid\u7684sql\u65e5\u5fd7\uff1f<\/h3>\n<\/p>\n<p><p>\u63a8\u8350\u4f7f\u7528Log4j\u3001Log4j2\u6216SLF4J\u7b49\u6d41\u884c\u7684\u65e5\u5fd7\u6846\u67b6\u6765\u8bb0\u5f55druid\u7684sql\u65e5\u5fd7\u3002\u8fd9\u4e9b\u65e5\u5fd7\u6846\u67b6\u5177\u6709\u4e30\u5bcc\u7684\u529f\u80fd\uff0c\u6613\u4e8e\u96c6\u6210\u548c\u4f7f\u7528\u3002<\/p>\n<\/p>\n<ul>\n<li>Log4j\uff1a\u662f\u4e00\u4e2a\u529f\u80fd\u5f3a\u5927\u7684\u65e5\u5fd7\u6846\u67b6\uff0c\u652f\u6301\u591a\u79cd\u65e5\u5fd7\u7ea7\u522b\u548c\u683c\u5f0f\u3002<\/li>\n<li>Log4j2\uff1a\u662fLog4j\u7684\u4e0b\u4e00\u4ee3\u7248\u672c\uff0c\u6027\u80fd\u66f4\u4f18\uff0c\u529f\u80fd\u66f4\u4e30\u5bcc\u3002<\/li>\n<li>SLF4J\uff1a\u662f\u4e00\u4e2a\u65e5\u5fd7\u95e8\u9762\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u5207\u6362\u4e0d\u540c\u7684\u65e5\u5fd7\u5b9e\u73b0\u3002<\/li>\n<\/ul>\n<p><h3>\u4e3a\u4ec0\u4e48\u5f00\u542fdruid\u7684sql\u65e5\u5fd7\u6253\u5370\u529f\u80fd\u5f88\u91cd\u8981\uff1f<\/h3>\n<\/p>\n<p><p>\u5f00\u542fdruid\u7684sql\u65e5\u5fd7\u6253\u5370\u529f\u80fd\u6709\u4ee5\u4e0b\u51e0\u70b9\u91cd\u8981\u6027\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u6027\u80fd\u4f18\u5316\uff1a\u901a\u8fc7\u5206\u6790\u6162\u67e5\u8be2\uff0c\u53ef\u4ee5\u4f18\u5316\u6570\u636e\u5e93\u6027\u80fd\u3002<\/li>\n<li>\u95ee\u9898\u6392\u67e5\uff1a\u5f53\u7cfb\u7edf\u51fa\u73b0\u95ee\u9898\u65f6\uff0c\u53ef\u4ee5\u901a\u8fc7\u65e5\u5fd7\u5feb\u901f\u5b9a\u4f4d\u95ee\u9898\u6240\u5728\u3002<\/li>\n<li>\u5b89\u5168\u5ba1\u8ba1\uff1a\u8bb0\u5f55SQL\u6267\u884c\u8fc7\u7a0b\uff0c\u6709\u52a9\u4e8e\u5b89\u5168\u5ba1\u8ba1\u548c\u5408\u89c4\u6027\u68c0\u67e5\u3002<\/li>\n<\/ul>\n<p><h3><b>\u5982\u4f55\u8bbe\u7f6eLog4j2\u6765\u8bb0\u5f55druid\u7684sql\u65e5\u5fd7\uff1f<\/b><\/h3>\n<\/p>\n<p><p>\u8981\u8bbe\u7f6eLog4j2\u8bb0\u5f55druid\u7684sql\u65e5\u5fd7\uff0c\u9996\u5148\u9700\u8981\u5728Log4j2\u7684\u914d\u7f6e\u6587\u4ef6\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u914d\u7f6e\uff1a<\/p>\n<\/p>\n<p><pre><code>Appenders:<\/p>\r\n<p>  Console: {Console}<\/p>\r\n<p>  DruidSQL: {DruidSQL}<\/p>\r\n\r\n<p>Loggers:<\/p>\r\n<p>  Druid:<\/p>\r\n<p>    level: info<\/p>\r\n<p>    AppenderRef: DruidSQL<\/p>\r\n\r\n<p>Appenders:<\/p>\r\n<p>  Console:<\/p>\r\n<p>    type: Console<\/p>\r\n<p>    target: System.out<\/p>\r\n\r\n<p>  DruidSQL:<\/p>\r\n<p>    type: Console<\/p>\r\n<p>    target: System.out<\/p>\r\n<p>    pattern: \"%d{yyyy-MM-dd HH:mm:ss} [%t] %-5level %logger{36} - %msg%n\"<\/p>\r\n<p><\/code><\/pre>\n<\/p>\n<p><h3><b>\u5982\u4f55\u901a\u8fc7SQL\u65e5\u5fd7\u5206\u6790\u6570\u636e\u5e93\u6027\u80fd\u74f6\u9888\uff1f<\/b><\/h3>\n<\/p>\n<p><p>\u901a\u8fc7\u5206\u6790SQL\u65e5\u5fd7\uff0c\u53ef\u4ee5\u627e\u5230\u4ee5\u4e0b\u6027\u80fd\u74f6\u9888\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u6162\u67e5\u8be2\uff1a\u6267\u884c\u65f6\u95f4\u8d85\u8fc7\u9884\u8bbe\u9608\u503c\u7684SQL\u8bed\u53e5\u3002<\/li>\n<li>\u7d22\u5f15\u7f3a\u5931\uff1a\u5bfc\u81f4\u67e5\u8be2\u6548\u7387\u4f4e\u4e0b\u7684SQL\u8bed\u53e5\u3002<\/li>\n<li>\u6570\u636e\u91cf\u8fc7\u5927\uff1a\u5bfc\u81f4\u67e5\u8be2\u6027\u80fd\u4e0b\u964d\u7684\u6570\u636e\u8868\u3002<\/li>\n<\/ul>\n<p><h3><b>\u5f00\u542fdruid\u7684sql\u65e5\u5fd7\u6253\u5370\u529f\u80fd\u4f1a\u5bf9\u7cfb\u7edf\u6027\u80fd\u4ea7\u751f\u5f71\u54cd\u5417\uff1f<\/b><\/h3>\n<\/p>\n<p><p>\u5f00\u542fdruid\u7684sql\u65e5\u5fd7\u6253\u5370\u529f\u80fd\u4f1a\u5bf9\u7cfb\u7edf\u6027\u80fd\u4ea7\u751f\u4e00\u5b9a\u7684\u5f71\u54cd\uff0c\u4f46\u901a\u5e38\u8fd9\u79cd\u5f71\u54cd\u662f\u5fae\u4e4e\u5176\u5fae\u7684\u3002\u5728\u5927\u591a\u6570\u60c5\u51b5\u4e0b\uff0c\u5f00\u542fsql\u65e5\u5fd7\u6253\u5370\u529f\u80fd\u4e0d\u4f1a\u5bf9\u7cfb\u7edf\u6027\u80fd\u4ea7\u751f\u660e\u663e\u5f71\u54cd\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>druid\u5f00\u542fsql\u65e5\u5fd7\u6253\u5370\u5185\u5bb9\u5305\u542b\u54ea\u4e9b\uff1f druid\u5f00\u542fsql\u65e5\u5fd7\u6253\u5370\u540e\uff0c\u53ef\u4ee5\u8bb0\u5f55\u67e5\u8be2\u8bed\u53e5\u3001\u6267\u884c\u65f6\u95f4\u3001SQL\u6267\u884c\u7ed3\u679c\u7b49\u4fe1\u606f\u3002\u5177\u4f53\u5305\u542b\u4ee5\u4e0b\u5185\u5bb9\uff1a SQL\u8bed\u53e5\uff1a\u663e\u793a\u6267\u884c\u7684SQL\u8bed\u53e5\u3002 \u6267\u884c\u65f6\u95f4\uff1a\u8bb0\u5f55SQL\u8bed\u53e5\u7684\u6267\u884c\u65f6\u95f4\u3002 SQL\u6267\u884c\u7ed3\u679c\uff1a\u663e\u793a&#8230;<\/p>\n","protected":false},"author":1,"featured_media":1241,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[344,338,99],"topic":[],"class_list":["post-1240","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-haiwai","tag-druid","tag-sql","tag-99"],"_links":{"self":[{"href":"https:\/\/www.hgfwq.com\/blog\/wp-json\/wp\/v2\/posts\/1240","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hgfwq.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hgfwq.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hgfwq.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hgfwq.com\/blog\/wp-json\/wp\/v2\/comments?post=1240"}],"version-history":[{"count":1,"href":"https:\/\/www.hgfwq.com\/blog\/wp-json\/wp\/v2\/posts\/1240\/revisions"}],"predecessor-version":[{"id":1243,"href":"https:\/\/www.hgfwq.com\/blog\/wp-json\/wp\/v2\/posts\/1240\/revisions\/1243"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.hgfwq.com\/blog\/wp-json\/wp\/v2\/media\/1241"}],"wp:attachment":[{"href":"https:\/\/www.hgfwq.com\/blog\/wp-json\/wp\/v2\/media?parent=1240"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hgfwq.com\/blog\/wp-json\/wp\/v2\/categories?post=1240"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hgfwq.com\/blog\/wp-json\/wp\/v2\/tags?post=1240"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.hgfwq.com\/blog\/wp-json\/wp\/v2\/topic?post=1240"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}