{"id":200535,"date":"2025-05-06T08:04:23","date_gmt":"2025-05-06T00:04:23","guid":{"rendered":"https:\/\/server.hk\/cnblog\/200535\/"},"modified":"2025-05-06T08:04:23","modified_gmt":"2025-05-06T00:04:23","slug":"mysql-%e6%97%a5%e6%9c%9f%e5%ad%97%e6%ae%b5%e8%a2%ab%e7%bd%ae%e4%b8%ba-null-%e5%a6%82%e4%bd%95%e6%8e%92%e6%9f%a5%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/200535\/","title":{"rendered":"MySQL \u65e5\u671f\u5b57\u6bb5\u88ab\u7f6e\u4e3a NULL \u5982\u4f55\u6392\u67e5\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>MySQL \u65e5\u671f\u5b57\u6bb5\u88ab\u7f6e\u4e3a NULL \u5982\u4f55\u6392\u67e5\uff1f <\/h1>\n<p>\u5b66\u4e60\u8981\u52aa\u529b\uff0c\u4f46\u662f\u4e0d\u8981\u6025\uff01\u4eca\u5929\u7684\u8fd9\u7bc7\u6587\u7ae0\u5c06\u4f1a\u4ecb\u7ecd\u5230\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5982\u679c\u4f60\u60f3\u6df1\u5165\u5b66\u4e60\uff0c\u53ef\u4ee5\u5173\u6ce8\u6211\uff01\u6211\u4f1a\u6301\u7eed\u66f4\u65b0\u76f8\u5173\u6587\u7ae0\u7684\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u90fd\u80fd\u6709\u6240\u5e2e\u52a9\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241107\/1730986790672cc32686394.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>\u5982\u4f55\u6392\u67e5 mysql \u8868\u4e2d\u5b57\u6bb5\u88ab\u7f6e\u4e3a null \u7684\u95ee\u9898\uff1f<\/strong><\/p>\n<p>\u5728 spring boot \u548c mysql 5.7 \u7684\u9879\u76ee\u4e2d\uff0c\u67d0\u4e2a\u8868\u4e2d\u7684\u65e5\u671f\u5b57\u6bb5\u51fa\u73b0\u4e86\u88ab\u4fee\u6539\u4e3a null \u7684\u95ee\u9898\uff0c\u6e90\u81ea\u672a\u77e5\u7684\u73af\u8282\u3002\u4e3a\u4e86\u89e3\u51b3\u8be5\u95ee\u9898\uff0c\u8003\u8651\u4ee5\u4e0b\u6392\u67e5\u9014\u5f84\uff1a<\/p>\n<p><strong>\u76d1\u63a7\u8868\u5b57\u6bb5\u53d8\u52a8<\/strong><\/p>\n<p>\u786e\u5b9e\u53ef\u4ee5\u8003\u8651\u76d1\u63a7\u6307\u5b9a\u8868\u7684\u5b57\u6bb5\u53d8\u52a8\u60c5\u51b5\u3002\u4e00\u79cd\u65b9\u6cd5\u662f\u4f7f\u7528 mysql \u7684\u89e6\u53d1\u5668\uff08triggers\uff09\u6765\u8bb0\u5f55\u6bcf\u6b21\u5b57\u6bb5\u503c\u7684\u4fee\u6539\u3002\u5f53\u5b57\u6bb5\u88ab\u4fee\u6539\u65f6\uff0c\u89e6\u53d1\u5668\u53ef\u4ee5\u5411\u4f60\u53d1\u9001\u7535\u5b50\u90ae\u4ef6\u6216\u5176\u4ed6\u901a\u77e5\u3002\u4ee5\u4e0b\u662f\u793a\u4f8b\u89e6\u53d1\u5668\u4ee3\u7801\uff1a<\/p>\n<pre>delimiter $$\ncreate trigger trigger_name after update on table_name\nfor each row\nbegin\n  -- \u53d1\u9001\u7535\u5b50\u90ae\u4ef6\u901a\u77e5\n  set @email = 'example@email.com';\n  set @subject = 'field updated to null';\n  set @message = concat('the field ', old.column_name, ' in table ', table_name, ' was updated to null.');\n  call mysql.rds_send_mail(@email, @subject, @message);\nend$$\ndelimiter ;<\/pre>\n<p>\u5728\u89e6\u53d1\u5668\u521b\u5efa\u540e\uff0c\u8bf7\u8bb0\u4f4f\u5728\u5b57\u6bb5\u53d1\u751f\u4fee\u6539\u65f6\u68c0\u67e5\u4f60\u7684\u901a\u77e5\u3002<\/p>\n<p><strong>\u68c0\u67e5\u4e8c\u8fdb\u5236\u65e5\u5fd7<\/strong><\/p>\n<p>mysql \u7684\u4e8c\u8fdb\u5236\u65e5\u5fd7\u8bb0\u5f55\u4e86\u5bf9\u6570\u636e\u5e93\u6240\u505a\u7684\u6240\u6709\u66f4\u6539\u3002\u4f60\u53ef\u4ee5\u67e5\u627e\u7279\u5b9a\u8868\u7684\u5173\u952e\u5b57\uff0c\u770b\u770b\u54ea\u6761 sql \u8bed\u53e5\u5c06\u5b57\u6bb5\u6539\u6210\u4e86 null\u3002\u8981\u6267\u884c\u6b64\u64cd\u4f5c\uff0c\u8bf7\u8f6c\u5230 mysql \u547d\u4ee4\u884c\u5e76\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre>mysqlbinlog \/path\/to\/binary-log.000001 | grep -E \"table_name|column_name|NULL\"<\/pre>\n<p>\u8fd9\u5c06\u8fc7\u6ee4\u4e8c\u8fdb\u5236\u65e5\u5fd7\uff0c\u4ec5\u663e\u793a\u4e0e\u76ee\u6807\u8868\u548c\u5b57\u6bb5\u76f8\u5173\u7684\u6761\u76ee\uff0c\u5e2e\u52a9\u4f60\u627e\u51fa\u5bfc\u81f4\u95ee\u9898\u7684 sql \u8bed\u53e5\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u300aMySQL \u65e5\u671f\u5b57\u6bb5\u88ab\u7f6e\u4e3a NULL \u5982\u4f55\u6392\u67e5\uff1f \u300b\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u5173\u4e8e\u7684\u8d44\u6599\u8bf7\u5173\u6ce8\u4e3b\u673a\u5b9d\u8d1d\u516c\u4f17\u53f7\uff01<\/p>\n<dl>\n<dt>\n <\/dt>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>MySQL \u65e5\u671f\u5b57\u6bb5\u88ab\u7f6e\u4e3a NU&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-200535","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/200535","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=200535"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/200535\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=200535"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=200535"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=200535"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}