{"id":1167,"date":"2016-07-19T17:57:23","date_gmt":"2016-07-19T09:57:23","guid":{"rendered":"http:\/\/www.yeetrack.com\/?p=1167"},"modified":"2016-07-19T17:58:18","modified_gmt":"2016-07-19T09:58:18","slug":"mysql-this-is-incompatible-with-sql_modeonly_full_group_by","status":"publish","type":"post","link":"https:\/\/www.yeetrack.com\/?p=1167","title":{"rendered":"mysql  this is incompatible with sql_mode=only_full_group_by"},"content":{"rendered":"<p>\u4f7f\u7528Ebean\u6267\u884c\u4e00\u6761sql\u8bed\u53e5\uff0cExpression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'offline_db.db.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by\uff0c\u539f\u56e0\u662f\u4e25\u683c\u6a21\u5f0f\u4e0b\uff0cmysql\u8981\u6c42\u6240\u6709\u5728group by\u4e2d\u51fa\u73b0\u7684\u5b57\u6bb5\uff0c\u5fc5\u987b\u5728select \u4e2d\u51fa\u73b0\u8fc7\uff0c\u4e0d\u8fc7\u6211\u4eec\u53ef\u4ee5\u8bbe\u7f6emysql \u5ffd\u7565\u8fd9\u79cd\u4e0d\u592a\u4e25\u683c\u7684sql\u8bed\u53e5\uff0c\u7ee7\u7eed\u6267\u884c<!--more--><\/p>\n<pre>set global sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';\nset session sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';\n<\/pre>\n<p>\u4e0b\u9762\u662f\u6709\u5173sql_mode\u7684\u4e00\u4e9b\u89e3\u91ca\uff1a<\/p>\n<p>sql_mode\u662f\u4e2a\u5f88\u5bb9\u6613\u88ab\u5ffd\u89c6\u7684\u53d8\u91cf\uff0c\u9ed8\u8ba4\u503c\u662f\u7a7a\u503c\uff0c\u5728\u8fd9\u79cd\u8bbe\u7f6e\u4e0b\u662f\u53ef\u4ee5\u5141\u8bb8\u4e00\u4e9b\u975e\u6cd5\u64cd\u4f5c\u7684\uff0c\u6bd4\u5982\u5141\u8bb8\u4e00\u4e9b\u975e\u6cd5\u6570\u636e\u7684\u63d2\u5165\u3002\u5728\u751f\u4ea7\u73af\u5883\u5fc5\u987b\u5c06\u8fd9\u4e2a\u503c\u8bbe\u7f6e\u4e3a\u4e25\u683c\u6a21\u5f0f\uff0c\u6240\u4ee5\u5f00\u53d1\u3001\u6d4b\u8bd5\u73af\u5883\u7684<a class=\"replace_word\" title=\"MySQL\u77e5\u8bc6\u5e93\" href=\"http:\/\/lib.csdn.net\/base\/14\" target=\"_blank\">\u6570\u636e\u5e93<\/a>\u4e5f\u5fc5\u987b\u8981\u8bbe\u7f6e\uff0c\u8fd9\u6837\u5728\u5f00\u53d1\u6d4b\u8bd5\u9636\u6bb5\u5c31\u53ef\u4ee5\u53d1\u73b0\u95ee\u9898<\/p>\n<p><strong>sql_mode\u5e38\u7528\u503c\u5982\u4e0b\uff1a<\/strong><br \/>\nONLY_FULL_GROUP_BY\uff1a<\/p>\n<p>\u5bf9\u4e8eGROUP BY\u805a\u5408\u64cd\u4f5c\uff0c\u5982\u679c\u5728SELECT\u4e2d\u7684\u5217\uff0c\u6ca1\u6709\u5728GROUP BY\u4e2d\u51fa\u73b0\uff0c\u90a3\u4e48\u8fd9\u4e2aSQL\u662f\u4e0d\u5408\u6cd5\u7684\uff0c\u56e0\u4e3a\u5217\u4e0d\u5728GROUP BY\u4ece\u53e5\u4e2d<br \/>\nNO_AUTO_VALUE_ON_ZERO\uff1a<\/p>\n<p>\u8be5\u503c\u5f71\u54cd\u81ea\u589e\u957f\u5217\u7684\u63d2\u5165\u3002\u9ed8\u8ba4\u8bbe\u7f6e\u4e0b\uff0c\u63d2\u51650\u6216NULL\u4ee3\u8868\u751f\u6210\u4e0b\u4e00\u4e2a\u81ea\u589e\u957f\u503c\u3002\u5982\u679c\u7528\u6237\u00a0\u5e0c\u671b\u63d2\u5165\u7684\u503c\u4e3a0\uff0c\u800c\u8be5\u5217\u53c8\u662f\u81ea\u589e\u957f\u7684\uff0c\u90a3\u4e48\u8fd9\u4e2a\u9009\u9879\u5c31\u6709\u7528\u4e86\u3002<br \/>\nSTRICT_TRANS_TABLES\uff1a<\/p>\n<p>\u5728\u8be5\u6a21\u5f0f\u4e0b\uff0c\u5982\u679c\u4e00\u4e2a\u503c\u4e0d\u80fd\u63d2\u5165\u5230\u4e00\u4e2a\u4e8b\u52a1\u8868\u4e2d\uff0c\u5219\u4e2d\u65ad\u5f53\u524d\u7684\u64cd\u4f5c\uff0c\u5bf9\u975e\u4e8b\u52a1\u8868\u4e0d\u505a\u9650\u5236<\/p>\n<p>NO_ZERO_IN_DATE\uff1a<\/p>\n<p>\u5728\u4e25\u683c\u6a21\u5f0f\u4e0b\uff0c\u4e0d\u5141\u8bb8\u65e5\u671f\u548c\u6708\u4efd\u4e3a\u96f6<br \/>\nNO_ZERO_DATE\uff1a<\/p>\n<p>\u8bbe\u7f6e\u8be5\u503c\uff0cmysql\u6570\u636e\u5e93\u4e0d\u5141\u8bb8\u63d2\u5165\u96f6\u65e5\u671f\uff0c\u63d2\u5165\u96f6\u65e5\u671f\u4f1a\u629b\u51fa\u9519\u8bef\u800c\u4e0d\u662f\u8b66\u544a\u3002<br \/>\nERROR_FOR_DIVISION_BY_ZERO\uff1a<\/p>\n<p>\u5728INSERT\u6216UPDATE\u8fc7\u7a0b\u4e2d\uff0c\u5982\u679c\u6570\u636e\u88ab\u96f6\u9664\uff0c\u5219\u4ea7\u751f\u9519\u8bef\u800c\u975e\u8b66\u544a\u3002\u5982\u00a0\u679c\u672a\u7ed9\u51fa\u8be5\u6a21\u5f0f\uff0c\u90a3\u4e48\u6570\u636e\u88ab\u96f6\u9664\u65f6MySQL\u8fd4\u56deNULL<br \/>\nNO_AUTO_CREATE_USER\uff1a<\/p>\n<p>\u7981\u6b62GRANT\u521b\u5efa\u5bc6\u7801\u4e3a\u7a7a\u7684\u7528\u6237<br \/>\nNO_ENGINE_SUBSTITUTION\uff1a<\/p>\n<p>\u5982\u679c\u9700\u8981\u7684\u5b58\u50a8\u5f15\u64ce\u88ab\u7981\u7528\u6216\u672a\u7f16\u8bd1\uff0c\u90a3\u4e48\u629b\u51fa\u9519\u8bef\u3002\u4e0d\u8bbe\u7f6e\u6b64\u503c\u65f6\uff0c\u7528\u9ed8\u8ba4\u7684\u5b58\u50a8\u5f15\u64ce\u66ff\u4ee3\uff0c\u5e76\u629b\u51fa\u4e00\u4e2a\u5f02\u5e38<br \/>\nPIPES_AS_CONCAT\uff1a<\/p>\n<p>\u5c06\"||\"\u89c6\u4e3a\u5b57\u7b26\u4e32\u7684\u8fde\u63a5\u64cd\u4f5c\u7b26\u800c\u975e\u6216\u8fd0\u7b97\u7b26\uff0c\u8fd9\u548cOracle\u6570\u636e\u5e93\u662f\u4e00\u6837\u7684\uff0c\u4e5f\u548c\u5b57\u7b26\u4e32\u7684\u62fc\u63a5\u51fd\u6570Concat\u76f8\u7c7b\u4f3c<br \/>\nANSI_QUOTES\uff1a<\/p>\n<p>\u542f\u7528ANSI_QUOTES\u540e\uff0c\u4e0d\u80fd\u7528\u53cc\u5f15\u53f7\u6765\u5f15\u7528\u5b57\u7b26\u4e32\uff0c\u56e0\u4e3a\u5b83\u88ab\u89e3\u91ca\u4e3a\u8bc6\u522b\u7b26<br \/>\nORACLE\u7684sql_mode\u8bbe\u7f6e\u7b49\u540c\uff1aPIPES_AS_CONCAT, ANSI_QUOTES, IGNORE_SPACE, NO_KEY_OPTIONS, NO_TABLE_OPTIONS, NO_FIELD_OPTIONS, NO_AUTO_CREATE_USER.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>\u5982\u679c\u4f7f\u7528mysql\uff0c\u4e3a\u4e86\u7ee7\u7eed\u4fdd\u7559\u5927\u5bb6\u4f7f\u7528oracle\u7684\u4e60\u60ef\uff0c\u53ef\u4ee5\u5bf9mysql\u7684sql_mode\u8bbe\u7f6e\u5982\u4e0b<\/strong>\uff1a<\/p>\n<p>&nbsp;<\/p>\n<p>\u5728my.cnf\u6dfb\u52a0\u5982\u4e0b\u914d\u7f6e<br \/>\n[mysqld]<br \/>\nsql_mode='ONLY_FULL_GROUP_BY,NO_AUTO_VALUE_ON_ZERO,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,<\/p>\n<p>ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION,PIPES_AS_CONCAT,ANSI_QUOTES'<\/p>\n<p>\u53c2\u8003\uff1a\u00a0http:\/\/blog.csdn.net\/wyzxg\/article\/details\/8787878<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f7f\u7528Ebean\u6267\u884c\u4e00\u6761sql\u8bed\u53e5\uff0cExpression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated c&#46;&#46;&#46;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"pgc_sgb_lightbox_settings":"","footnotes":""},"categories":[34],"tags":[63,8,31],"class_list":["post-1167","post","type-post","status-publish","format-standard","hentry","category-software","tag-ebean","tag-java","tag-sql"],"views":3778,"_links":{"self":[{"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/posts\/1167","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1167"}],"version-history":[{"count":1,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/posts\/1167\/revisions"}],"predecessor-version":[{"id":1168,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/posts\/1167\/revisions\/1168"}],"wp:attachment":[{"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1167"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1167"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1167"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}