{"id":588,"date":"2023-07-20T11:02:11","date_gmt":"2023-07-20T03:02:11","guid":{"rendered":"https:\/\/www.db2go.net\/?p=588"},"modified":"2023-07-20T11:04:21","modified_gmt":"2023-07-20T03:04:21","slug":"mysql%e8%bf%81%e7%a7%bb%e6%95%b0%e6%8d%ae%e6%8a%a5%e9%94%99","status":"publish","type":"post","link":"https:\/\/www.db2go.net\/?p=588","title":{"rendered":"MySQL\u8fc1\u79fb\u6570\u636e\u62a5\u9519"},"content":{"rendered":"<h3>\u95ee\u9898<\/h3>\n<p><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/www.db2go.net\/wp-content\/uploads\/2023\/07\/wp_editor_md_a2b2598a1e2d116f36bf47feace5999e.jpg\"><img decoding=\"async\" src=\"https:\/\/www.db2go.net\/wp-content\/uploads\/2023\/07\/wp_editor_md_a2b2598a1e2d116f36bf47feace5999e.jpg\" alt=\"\" \/><\/a><\/p>\n<h3>\u89e3\u51b3\u8fc7\u7a0b<\/h3>\n<ol>\n<li>\u67e5\u770bSQL_MODE<\/li>\n<\/ol>\n<pre><code class=\"language-SQL line-numbers\">show variables like 'sql_mode';\n\n\u6216\u8005\uff1a\nselect @@GLOBAL.sql_mode\n<\/code><\/pre>\n<p>\u53d1\u73b0\uff1a<\/p>\n<pre><code class=\"language-SQL line-numbers\">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<\/code><\/pre>\n<p>\u5c31\u662f<code>NO_ZERO_IN_DATE<\/code>\u548c<code>NO_ZERO_DATE<\/code>\u8fd9\u4e24\u4e2a\u7684\u9505\u3002<\/p>\n<ol start=\"2\">\n<li>\u4fee\u6539SQL_MODE<\/li>\n<\/ol>\n<p>\u53ea\u8ba9\u5f53\u524d\u7684session\u751f\u6548\uff0c\u6267\u884c\u547d\u4ee4:<\/p>\n<pre><code class=\"language-SQL line-numbers\"> SET @@GLOBAL.sql_mode='STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'\n<\/code><\/pre>\n<p>\u5982\u679c\u8981\u8ba9\u5168\u5c40\u751f\u6548\uff0c\u5728my.cnf\u91cc\u9762\uff0c\u628a<code>NO_ZERO_IN_DATE,NO_ZERO_DATE<\/code>\u53bb\u6389\uff0c\u518d\u91cd\u542f\u670d\u52a1\u5668\u3002<\/p>\n<h3>\u62d3\u5c55\u77e5\u8bc6<\/h3>\n<p>MySQL\u7684sql_mode\u662f\u4e00\u4e2a\u7cfb\u7edf\u53d8\u91cf\uff0c\u5b83\u53ef\u4ee5\u5f71\u54cdMySQL SQL\u8bed\u53e5\u7684\u6267\u884c\u65b9\u5f0f\u3002sql_mode\u53d8\u91cf\u5305\u542b\u4e00\u7cfb\u5217\u4e0d\u540c\u7684\u6a21\u5f0f\uff0c\u8fd9\u4e9b\u6a21\u5f0f\u53ef\u4ee5\u542f\u7528\u6216\u7981\u7528\u67d0\u4e9b\u884c\u4e3a\u548c\u68c0\u67e5\u3002\u8fd9\u53ef\u4ee5\u8ba9\u66f4\u597d\u5730\u63a7\u5236SQL\u67e5\u8be2\u7684\u884c\u4e3a\uff0c\u5e76\u53ef\u4ee5\u5e2e\u52a9\u627e\u5230\u5e76\u4fee\u590d\u6f5c\u5728\u7684\u95ee\u9898\u3002<\/p>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e9bsql_mode\u5e38\u89c1\u6a21\u5f0f\u7684\u4f8b\u5b50\uff1a<\/p>\n<ul>\n<li>ONLY_FULL_GROUP_BY\uff1a\u5f53\u542f\u7528\u6b64\u6a21\u5f0f\u65f6\uff0cGROUP BY\u5b50\u53e5\u5fc5\u987b\u5305\u542b\u6240\u6709\u5728SELECT\u5b50\u53e5\u4e2d\u672a\u4f7f\u7528\u805a\u5408\u51fd\u6570\u7684\u5217\u3002\u8fd9\u53ef\u4ee5\u9632\u6b62\u56e0\u4f9d\u8d56\u4e8eMySQL\u7684\u6269\u5c55GROUP BY\u884c\u4e3a\u800c\u4ea7\u751f\u4e0d\u786e\u5b9a\u7684\u7ed3\u679c\u3002<\/p>\n<\/li>\n<li>\n<p>STRICT_TRANS_TABLES\u548cSTRICT_ALL_TABLES\uff1a\u5f53\u542f\u7528\u8fd9\u4e9b\u6a21\u5f0f\u65f6\uff0cMySQL\u5c06\u5bf9\u67d0\u4e9b\u53ef\u80fd\u66f4\u6539\u6570\u636e\u7684\u64cd\u4f5c\u6267\u884c\u66f4\u4e25\u683c\u7684\u9519\u8bef\u68c0\u67e5\u3002\u4f8b\u5982\uff0c\u8bd5\u56fe\u5c06\u4e00\u4e2a\u8d85\u51fa\u5217\u8303\u56f4\u7684\u503c\u63d2\u5165\u5217\u5c06\u5bfc\u81f4\u9519\u8bef\uff0c\u800c\u4e0d\u662f\u5c06\u503c\u8c03\u6574\u5230\u5217\u8303\u56f4\u7684\u6700\u5927\u6216\u6700\u5c0f\u503c\u3002<\/p>\n<\/li>\n<li>\n<p>NO_ZERO_DATE\uff0cNO_ZERO_IN_DATE\u548cERROR_FOR_DIVISION_BY_ZERO\uff1a\u5f53\u542f\u7528\u8fd9\u4e9b\u6a21\u5f0f\u65f6\uff0cMySQL\u5c06\u5bf9\u65e5\u671f\u548c\u96f6\u9664\u64cd\u4f5c\u6267\u884c\u66f4\u4e25\u683c\u7684\u9519\u8bef\u68c0\u67e5\u3002<\/p>\n<\/li>\n<li>\n<p>NO_AUTO_VALUE_ON_ZERO\uff1a\u542f\u7528\u6b64\u6a21\u5f0f\u65f6\uff0c\u5411AUTO_INCREMENT\u5217\u63d2\u51650\u6216NULL\u5c06\u4e0d\u4f1a\u751f\u6210\u65b0\u7684\u81ea\u52a8\u589e\u91cf\u503c\uff0c\u800c\u662f\u5c06\u503c\u8bbe\u4e3a0\u6216NULL\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0bSQL\u8bed\u53e5\u67e5\u770b\u5f53\u524d\u7684sql_mode\u8bbe\u7f6e\uff1a<\/p>\n<pre><code class=\"language-SQL line-numbers\">SELECT @@sql_mode;\n<\/code><\/pre>\n<p>\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0bSQL\u8bed\u53e5\u8bbe\u7f6esql_mode\uff1a<\/p>\n<pre><code class=\"language-SQL line-numbers\">SET sql_mode = 'modes';\n<\/code><\/pre>\n<p>\u5176\u4e2d&#8217;modes&#8217;\u662f\u60f3\u8981\u8bbe\u7f6e\u7684\u6a21\u5f0f\uff0c\u591a\u4e2a\u6a21\u5f0f\u4e4b\u95f4\u7528\u9017\u53f7\u5206\u9694\u3002<\/p>\n<blockquote><p>\n  \u6ce8\u610f\uff0csql_mode\u7684\u8bbe\u7f6e\u53ea\u5bf9\u5f53\u524d\u4f1a\u8bdd\u6709\u6548\u3002\u5982\u679c\u60f3\u8981\u6c38\u4e45\u6539\u53d8sql_mode\u7684\u8bbe\u7f6e\uff0c\u9700\u8981\u5728MySQL\u7684\u914d\u7f6e\u6587\u4ef6\u4e2d\u8bbe\u7f6e\u3002\u8fd9\u901a\u5e38\u5728my.cnf\u6216my.ini\u6587\u4ef6\u4e2d\u7684[mysqld]\u90e8\u5206\u8fdb\u884c\u3002\n<\/p><\/blockquote>\n<p>\u5728\u8bbe\u7f6esql_mode\u65f6\uff0c\u8981\u5c0f\u5fc3\u786e\u4fdd\u4e86\u89e3\u6bcf\u4e2a\u6a21\u5f0f\u7684\u5f71\u54cd\uff0c\u56e0\u4e3a\u9519\u8bef\u7684\u8bbe\u7f6e\u53ef\u80fd\u4f1a\u5bfc\u81f4SQL\u67e5\u8be2\u65e0\u6cd5\u6309\u9884\u671f\u8fd0\u884c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u95ee\u9898 \u89e3\u51b3\u8fc7\u7a0b \u67e5\u770bSQL_MODE show variables like &#8216;sql_mode&#8217;; \u6216\u8005\uff1a &hellip;<\/p>\n <a href=\"https:\/\/www.db2go.net\/?p=588\" title=\"MySQL\u8fc1\u79fb\u6570\u636e\u62a5\u9519\" class=\"entry-more-link\"><span>Read More<\/span> <span class=\"screen-reader-text\">MySQL\u8fc1\u79fb\u6570\u636e\u62a5\u9519<\/span><\/a>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"Layout":"","footnotes":""},"categories":[5],"tags":[],"class_list":["entry","author-suredandan","post-588","post","type-post","status-publish","format-standard","category-mysql"],"views":1678,"_links":{"self":[{"href":"https:\/\/www.db2go.net\/index.php?rest_route=\/wp\/v2\/posts\/588","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.db2go.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.db2go.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.db2go.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.db2go.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=588"}],"version-history":[{"count":3,"href":"https:\/\/www.db2go.net\/index.php?rest_route=\/wp\/v2\/posts\/588\/revisions"}],"predecessor-version":[{"id":591,"href":"https:\/\/www.db2go.net\/index.php?rest_route=\/wp\/v2\/posts\/588\/revisions\/591"}],"wp:attachment":[{"href":"https:\/\/www.db2go.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=588"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.db2go.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=588"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.db2go.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=588"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}