{"id":46224,"date":"2019-09-02T09:14:26","date_gmt":"2019-09-02T01:14:26","guid":{"rendered":"http:\/\/www.xyryd.com\/?p=46224"},"modified":"2019-09-02T09:14:28","modified_gmt":"2019-09-02T01:14:28","slug":"mysql-%e5%87%ba%e7%8e%b0-which-is-not-functionally-dependent-on-columns-in-group-by-clause-this-is-incompatible-with-sql_modeonly_full_group_by%e9%94%99%e8%af%af-%e8%a7%a3%e5%86%b3%e5%8a%9e%e6%b3%95","status":"publish","type":"post","link":"http:\/\/www.xyryd.com\/46224.html","title":{"rendered":"MySQL \u51fa\u73b0 which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by\u9519\u8bef \u89e3\u51b3\u529e\u6cd5 \u56fe\u6587\u6559\u7a0b"},"content":{"rendered":"\n

\u8001\u5b63\u5728\u63a5\u89e6\u5230\u7684\u4e00\u4e2a\u9879\u76ee\u4e2d\uff0c\u5bfc\u5165MYSQL\u6587\u4ef6\u4e4b\u540e\u51fa\u73b0\u4e86\u9519\u8bef\uff0c\u5177\u4f53\u9519\u8bef\u5982\u4e0b\uff1a<\/p>\n\n\n\n

Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column ‘poweridc.t.id’ which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by<\/p><\/blockquote>\n\n\n\n

\u67e5\u8be2MySQL\u7248\u672c\u53ef\u4ee5\u5728\u547d\u4ee4\u884c\u6a21\u5f0f\u521a\u8fde\u63a5\u4e0a\u6570\u636e\u5e93\u65f6\u5c31\u80fd\u770b\u5230,\u6216\u8005\u5728\u8fdb\u5165mysql\u540e\u4f7f\u7528\u547d\u4ee4:status\u67e5\u770b\u7248\u672c\u53f7,<\/p>\n\n\n\n

\u65e2\u7136\u662f\u7248\u672c\u7684\u95ee\u9898,\u90a3\u5c31\u67e5\u8be2\u4e00\u4e0b\u914d\u7f6e\u770b\u770b\u5177\u4f53\u7684\u60c5\u51b5,\u547d\u4ee4\u884c\u8fde\u63a5\u4e0a\u6570\u636e\u5e93,\u518d\u8f93\u5165\u547d\u4ee4:<\/p>\n\n\n\n

select @@sql_mode<\/strong>;<\/pre>\n\n\n\n

sql_mode = ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION<\/p><\/blockquote>\n\n\n\n

<\/figure>\n\n\n\n

\u5176\u4e2dONLY_FULL_GROUP_BY\u5c31\u662f\u9020\u6210\u8fd9\u4e2a\u9519\u8bef\u7684\u7f6a\u9b41\u7978\u9996\u4e86,<\/p>\n\n\n\n

\u5bf9\u4e8egroup by\u805a\u5408\u64cd\u4f5c,\u5982\u679c\u5728select\u4e2d\u7684\u5217\u6ca1\u6709\u5728group by\u4e2d\u51fa\u73b0,\u90a3\u4e48\u8fd9\u4e2aSQL\u662f\u4e0d\u5408\u6cd5\u7684,\u56e0\u4e3a\u5217\u4e0d\u5728group by\u4ece\u53e5\u4e2d,\u6240\u4ee5\u8bbe\u7f6e\u4e86sql_mode=only_full_group_by \u7684\u6570\u636e\u5e93,\u5728\u4f7f\u7528group by\u65f6\u5c31\u4f1a\u62a5\u9519,<\/p>\n\n\n\n

\u65e2\u7136\u77e5\u9053\u4e86\u95ee\u9898,\u90a3\u4e48\u4fee\u6539\u8fd9\u4e2a\u914d\u7f6e\u5c31\u53ef\u4ee5\u4e86,\u627e\u5230MySQL\u7684\u914d\u7f6e\u6587\u4ef6,\u5728linux\u7cfb\u7edf\u4e0a\/etc\/my.cnf\u6587\u4ef6,\u67e5\u8be2sql_mode\u5b57\u6bb5,\u6211\u5e76\u6ca1\u6709\u5728\u914d\u7f6e\u6587\u4ef6\u4e2d\u627e\u5230\u8fd9\u4e2a\u5173\u952e\u5b57,\u6240\u4ee5\u6211\u624b\u52a8\u6dfb\u52a0\u8fdb\u53bb:<\/p>\n\n\n\n

sql_mode = STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION<\/code><\/pre>\n\n\n\n

\u9700\u8981\u6ce8\u610f\u7684\u4e00\u70b9\u662f\u4e00\u5b9a\u8981\u6dfb\u52a0\u5728[mysqld]\u914d\u7f6e\u5185,\u8fd9\u6837\u6dfb\u52a0\u5b8c\u540e\u91cd\u542fmysql\u624d\u4f1a\u751f\u6548,\u9000\u51fa\u6570\u636e\u5e93:exit,\u91cd\u542f\u547d\u4ee4:<\/p>\n\n\n\n

service mysqld restart;<\/code><\/pre>\n\n\n\n

\u5237\u65b0\u9875\u9762\u62a5\u9519\u4fe1\u606f\u6d88\u5931\u6210\u529f\u89e3\u51b3,\u518d\u6b21\u8fde\u63a5\u4e0a\u6570\u636e\u5e93\u67e5\u770bsql_mode\u914d\u7f6e<\/p>\n\n\n\n

select @@sql_mode;<\/code><\/pre>\n\n\n\n

\u5230\u6b64\u5df2\u7ecf\u6210\u529f\u89e3\u51b3\u4e86\u8fd9\u4e2a\u95ee\u9898\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

\u8001\u5b63\u5728\u63a5\u89e6\u5230\u7684\u4e00\u4e2a\u9879\u76ee\u4e2d\uff0c\u5bfc\u5165MYSQL\u6587\u4ef6\u4e4b\u540e\u51fa\u73b0\u4e86\u9519\u8bef\uff0c\u5177\u4f53\u9519\u8bef\u5982\u4e0b\uff1a Expression #1 of […]<\/p>\n","protected":false},"author":1,"featured_media":43382,"comment_status":"open","ping_status":"closed","sticky":false,"template":"single-with-sidebar","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[17,149,23],"aioseo_notices":[],"_links":{"self":[{"href":"http:\/\/www.xyryd.com\/wp-json\/wp\/v2\/posts\/46224"}],"collection":[{"href":"http:\/\/www.xyryd.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.xyryd.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.xyryd.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.xyryd.com\/wp-json\/wp\/v2\/comments?post=46224"}],"version-history":[{"count":0,"href":"http:\/\/www.xyryd.com\/wp-json\/wp\/v2\/posts\/46224\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.xyryd.com\/wp-json\/wp\/v2\/media\/43382"}],"wp:attachment":[{"href":"http:\/\/www.xyryd.com\/wp-json\/wp\/v2\/media?parent=46224"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.xyryd.com\/wp-json\/wp\/v2\/categories?post=46224"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.xyryd.com\/wp-json\/wp\/v2\/tags?post=46224"}],"curies":[{"name":"wp","href":"http:\/\/api.w.org\/{rel}","templated":true}]}}