{"id":3815,"date":"2019-01-29T14:42:35","date_gmt":"2019-01-29T06:42:35","guid":{"rendered":"http:\/\/www.xttblog.com\/?p=3815"},"modified":"2019-01-29T14:42:35","modified_gmt":"2019-01-29T06:42:35","slug":"%e6%b3%aa%e5%a5%94%ef%bc%8c%e5%90%8c%e4%ba%8b%e6%89%a7%e8%a1%8c-update-%e8%af%ad%e5%8f%a5%e6%b2%a1%e6%9c%89%e6%b7%bb%e5%8a%a0-where-%e6%9d%a1%e4%bb%b6%ef%bc%81","status":"publish","type":"post","link":"https:\/\/www.xttblog.com\/?p=3815","title":{"rendered":"\u6cea\u5954\uff0c\u540c\u4e8b\u6267\u884c update \u8bed\u53e5\u6ca1\u6709\u6dfb\u52a0 where \u6761\u4ef6\uff01"},"content":{"rendered":"<p>\n\t\u8fc7\u5e74\u4e5f\u4e0d\u80fd\u5b89\u7a33\u554a\uff0c\u6700\u8fd1\u51e0\u5929\u5927\u5bb6\u90fd\u6ca1\u5fc3\u5de5\u4f5c\u4e86\uff0c\u5de5\u4f5c\u91cf\u4e5f\u5c11\u3002\u4f46\u662f\u4e00\u4e9b\u540c\u4e8b\u9ad8\u5174\u8fc7\u5ea6\u4e86\uff0c\u6267\u884c update \u8bed\u53e5\u7adf\u7136\u6ca1\u6709\u6dfb\u52a0 where \u6761\u4ef6\uff01\n<\/p>\n<p>\n\tWhat\uff1f\u7adf\u7136\u8fd9\u4e48\u725bX\uff0c\u65e5\u5929\u4e86\u3002\u8fd9\u6837\u7684\u540c\u4e8b\u957f\u7684\u5e05\u5417\uff1f\n<\/p>\n<p>\n\t<img decoding=\"async\" alt=\"\u6211\u7684\u5185\u5fc3\u662f\u5d29\u6e83\u7684\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/wx1.sinaimg.cn\/large\/8fa5dcfcgy1fznfzdvx6mj2088088n0m.jpg\" style=\"width: 296px;height: 296px\" \/>\n<\/p>\n<p>\n\t\u5fae\u4fe1\u7fa4\u91cc\uff0c\u4e00\u8fde\u4e32\u7684\u53cd\u6620\uff0c\u6211\u770b\u4e86\u90fd\u8981\u5d29\u6e83\u3002\u8fd8\u597d\uff0c\u8fd9\u6b21\u4e8b\u6545\u662f\u53d1\u751f\u5728\u6d4b\u8bd5\u73af\u5883\uff01\n<\/p>\n<p>\n\t<img decoding=\"async\" alt=\"\u4e0d\u5e78\u4e2d\u7684\u4e07\u5e78\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/wx1.sinaimg.cn\/large\/8fa5dcfcgy1fzng0d18ezj206y06wq3m.jpg\" style=\"width: 250px;height: 248px\" \/>\n<\/p>\n<p>\n\t\u4f46\u662f\u6d4b\u8bd5\u73af\u5883\u4e5f\u4e0d\u80fd\u4e71\u64cd\u4f5c\u4e0d\u662f\uff0c\u4f60\u628a\u6d4b\u8bd5\u73af\u5883\u641e\u574f\u4e86\uff0c\u6d4b\u8bd5\u56e2\u961f\u8fd8\u600e\u4e48\u8fdb\u884c\uff01\u8fd9\u4e2a\u9505\u8c01\u6765\u80cc\uff1f\n<\/p>\n<p>\n\t\u867d\u7136\uff0c\u540c\u4e8b\u5728\u64cd\u4f5c\u4e0a\u6709\u4e9b\u95ee\u9898\uff0c\u4f46\u8fd9\u4e2a\u9505\u4e0d\u80fd\u5168\u6263\u4ed6\u5934\u4e0a\uff0c\u6211\u7ed9\u5927\u5bb6\u7684\u6743\u9650\u592a\u5927\u4e86\u4e5f\u662f\u4e00\u4e2a\u95ee\u9898\u3002\u6240\u4ee5\uff0c\u6211\u5148\u6062\u590d\u4e8b\u6545\u73b0\u573a\uff0c\u7136\u540e\u53c8\u914d\u7f6e\u4e86\u4e00\u70b9\u5b89\u5168\u9650\u5236\uff0cupdate\u3001delete \u76f8\u5173\u64cd\u4f5c\uff0c\u6ca1\u6709 where \u6761\u4ef6\uff0c\u4e0d\u80fd\u6267\u884c SQL\u3002\n<\/p>\n<p>\n\t\u4e3a\u4e86\u6f14\u793a\u6211\u7684\u6062\u590d\u64cd\u4f5c\uff0c\u6211\u5148\u7ed9\u5927\u5bb6\u7b80\u5316\u4e00\u4e0b\u6211\u7684\u6570\u636e\u8868\u3002\n<\/p>\n<pre class=\"brush:sql;\">\r\ncreate table xttblog (\r\n    id int unsigned not null auto_increment,\r\n    name char(20) not null,\r\n    sex enum(&#039;f&#039;,&#039;m&#039;) not null default &#039;m&#039;,\r\n    address varchar(30) not null,\r\n    primary key(id)\r\n);<\/pre>\n<p>\n\t\u5047\u8bbe\u91cc\u9762\u73b0\u5728\u6709 10 \u4e07\u6761\u6570\u636e\u3002\u73b0\u5728\u9700\u8981\u5c06 id \u7b49\u4e8e 88 \u7684\u7528\u6237\u7684\u5730\u5740\u6539\u4e3a&ldquo;\u4e0a\u6d77&rdquo;\uff0c\u4f46\u662f update \u65f6\u6ca1\u6709\u6dfb\u52a0 where \u6761\u4ef6\u3002\n<\/p>\n<pre class=\"brush:sql;\">\r\nupdate xttblog set address = &#039;\u4e0a\u6d77&#039;;<\/pre>\n<p>\n\t\u4e8b\u6545\u53d1\u751f\u540e\uff0c\u6211\u4eec\u73b0\u5728\u5f00\u59cb\u6062\u590d\uff0c\u5728\u7ebf\u4e0a\u7684\u8bdd\uff0c\u5e94\u8be5\u6bd4\u8f83\u590d\u6742\uff0c\u8981\u5148\u8fdb\u884c\u9501\u8868\uff0c\u4ee5\u514d\u6570\u636e\u518d\u6b21\u88ab\u6c61\u67d3\u3002\u9501\u8868\uff0c\u5c31\u662f\u67e5\u770b\u6b63\u5728\u5199\u54ea\u4e2a\u4e8c\u8fdb\u5236\u65e5\u5fd7\u6587\u4ef6\u3002\n<\/p>\n<pre class=\"brush:sql;\">\r\nlock tables xttblog read;\r\n-- \u67e5\u770b\u72b6\u6001\r\nshow master status;<\/pre>\n<p>\n\t<img decoding=\"async\" alt=\"show master status\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/wx1.sinaimg.cn\/large\/8fa5dcfcgy1fzng3i6qfxj20du03uglw.jpg\" style=\"width: 498px;height: 138px\" \/>\n<\/p>\n<p>\n\t\u5206\u6790\u4e8c\u8fdb\u5236\u65e5\u5fd7 mysql-bin.000024\uff0c\u5e76\u4e14\u5728\u5176\u4e2d\u627e\u5230\u76f8\u5173\u8bb0\u5f55\uff0c\u5728\u66f4\u65b0\u65f6\u662f address=&#039;\u4e0a\u6d77&#039;\uff0c\u6211\u4eec\u53ef\u4ee5\u5728\u65e5\u5fd7\u4e2d\u8fc7\u6ee4\u51fa\u6765\u3002\n<\/p>\n<pre class=\"brush:bash;\">\r\nmysqlbinlog --no-defaults -v -v --base64-output=DECODE-ROWS mysql-bin.000024 | grep -B 15 &#039;\u4e0a\u6d77&#039;<\/pre>\n<p>\n\t\u8fc7\u6ee4\u5185\u5bb9\u5982\u4e0b\uff1a\n<\/p>\n<pre class=\"brush:sql;\">\r\n# at 1629\r\n# at 1679\r\n#140305 10:52:24 server id 1  end_log_pos 1679  Table_map: `db01`.`xttblog` mapped to number 38\r\n#140305 10:52:24 server id 1  end_log_pos 1825  Update_rows: table id 38 flags: STMT_END_F\r\n### UPDATE db01.xttblog\r\n### WHERE\r\n###   @1=1 \/* INT meta=0 nullable=0 is_null=0 *\/\r\n###   @2=&#039;daiiy&#039; \/* STRING(60) meta=65084 nullable=0 is_null=0 *\/\r\n###   @3=2 \/* ENUM(1 byte) meta=63233 nullable=0 is_null=0 *\/\r\n###   @4=&#039;\u5e7f\u5dde&#039; \/* VARSTRING(90) meta=90 nullable=0 is_null=0 *\/\r\n### SET\r\n###   @1=1 \/* INT meta=0 nullable=0 is_null=0 *\/\r\n###   @2=&#039;daiiy&#039; \/* STRING(60) meta=65084 nullable=0 is_null=0 *\/\r\n###   @3=2 \/* ENUM(1 byte) meta=63233 nullable=0 is_null=0 *\/\r\n###   @4=&#039;\u4e0a\u6d77&#039; \/* VARSTRING(90) meta=90 nullable=0 is_null=0 *\/\r\n### UPDATE db01.xttblog\r\n### WHERE\r\n###   @1=2 \/* INT meta=0 nullable=0 is_null=0 *\/\r\n###   @2=&#039;tom&#039; \/* STRING(60) meta=65084 nullable=0 is_null=0 *\/\r\n###   @3=1 \/* ENUM(1 byte) meta=63233 nullable=0 is_null=0 *\/\r\n###   @4=&#039;shanghai&#039; \/* VARSTRING(90) meta=90 nullable=0 is_null=0 *\/\r\n### SET\r\n###   @1=2 \/* INT meta=0 nullable=0 is_null=0 *\/\r\n###   @2=&#039;tom&#039; \/* STRING(60) meta=65084 nullable=0 is_null=0 *\/\r\n###   @3=1 \/* ENUM(1 byte) meta=63233 nullable=0 is_null=0 *\/\r\n###   @4=&#039;\u4e0a\u6d77&#039; \/* VARSTRING(90) meta=90 nullable=0 is_null=0 *\/\r\n### UPDATE db01.xttblog\r\n### WHERE\r\n###   @1=3 \/* INT meta=0 nullable=0 is_null=0 *\/\r\n###   @2=&#039;liany&#039; \/* STRING(60) meta=65084 nullable=0 is_null=0 *\/\r\n###   @3=2 \/* ENUM(1 byte) meta=63233 nullable=0 is_null=0 *\/\r\n###   @4=&#039;\u5317\u4eac&#039; \/* VARSTRING(90) meta=90 nullable=0 is_null=0 *\/\r\n### SET\r\n###   @1=3 \/* INT meta=0 nullable=0 is_null=0 *\/\r\n###   @2=&#039;liany&#039; \/* STRING(60) meta=65084 nullable=0 is_null=0 *\/\r\n###   @3=2 \/* ENUM(1 byte) meta=63233 nullable=0 is_null=0 *\/\r\n###   @4=&#039;\u73e0\u6d77&#039; \/* VARSTRING(90) meta=90 nullable=0 is_null=0 *\/<\/pre>\n<p>\n\t\u53ef\u4ee5\u770b\u89c1\u91cc\u9762\u8bb0\u5f55\u4e86\u6bcf\u4e00\u884c\u7684\u53d8\u5316\uff0c\u8fd9\u4e5f\u662f binglog \u683c\u5f0f\u8981\u4e00\u5b9a\u662f row \u624d\u884c\u7684\u539f\u56e0\u3002\u5176\u4e2d @1,@2,@3,@4 \u5206\u522b\u5bf9\u5e94\u8868\u4e2d id,name,sex,address \u5b57\u6bb5\u3002\u76f8\u4fe1\u5927\u5bb6\u770b\u5230\u8fd9\u91cc\u6709\u70b9\u660e\u767d\u4e86\u5427\uff0c\u6211\u4eec\u53ea\u9700\u8981\u5c06\u76f8\u5173\u8bb0\u5f55\u8f6c\u6362\u4e3a sql \u8bed\u53e5\uff0c\u91cd\u65b0\u5bfc\u5165\u6570\u636e\u5e93\u5373\u53ef\u5b8c\u6210\u6570\u636e\u6062\u590d\u3002\n<\/p>\n<p>\n\t\u5173\u4e8e\u8fc7\u6ee4\u5904\u7406\u6210 SQL \u8bed\u53e5\u7684\u5185\u5bb9\uff0c\u6211\u5c31\u8865\u8d34\u4e86\u3002\u6211\u662f\u901a\u8fc7 shell \u6765\u5b9e\u73b0\u7684\uff0c\u4f60\u4eec\u4e5f\u53ef\u4ee5\u4f7f\u7528 binlog2sql \u5de5\u5177\uff0c\u8fd9\u4e2a\u5de5\u5177\u73b0\u5728\u56de\u6eda\u66f4\u52a0\u65b9\u4fbf\u3002\n<\/p>\n<p>\n\t\u8fc7\u6ee4\u5b8c\u4e86\u4e4b\u540e\uff0c\u6211\u4eec\u5728\u5bfc\u5165\u6570\u636e\u3002\u89e3\u9501\u8868\u3002\n<\/p>\n<pre class=\"brush:sql;\">\r\nsource xttblog_recovery.sql;\r\nunlock tables;<\/pre>\n<p>\n\t\u5b8c\u7f8e\uff0c\u73b0\u5728\u6570\u636e\u5168\u90e8\u90fd\u6062\u590d\u56de\u6765\u4e86\u3002\n<\/p>\n<p>\n\t<img decoding=\"async\" alt=\"MySQL \u6570\u636e\u6062\u590d\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/wx1.sinaimg.cn\/large\/8fa5dcfcgy1fzng7e5xmmj20aw0at0uz.jpg\" style=\"width: 392px;height: 389px\" \/>\n<\/p>\n<p>\n\t\u4f46\u662f\u6743\u9650\u95ee\u9898\uff0c\u8fd8\u8981\u52a0\u4ee5\u9650\u5236\u3002\u4e8e\u662f\u6211\u5728 MySQL \u7684\u914d\u7f6e\u6587\u4ef6\u4e2d\u52a0\u5165\u4e86 safe-updates \u914d\u7f6e\u3002\u8fd9\u6837\uff0c\u518d\u6709\u4e0d\u52a0\u6761\u4ef6\u7684\u66f4\u65b0\u548c\u5220\u9664\u64cd\u4f5c\uff0c\u90fd\u4f1a\u5931\u8d25\u3002\u63d0\u793a\uff1aERROR 1175 (HY000): You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column\u3002<\/p>\n<!-- <audio autoplay=\"autoplay\" height=\"100\" width=\"100\" hidden=\"true\"><source src=\"https:\/\/c.coka.la\/orAvPR.mp3\" type=\"audio\/mp3\"\/><\/audio><img decoding=\"async\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/ws3.sinaimg.cn\/large\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/> --><p><!-- <img decoding=\"async\" src=\"https:\/\/raw.githubusercontent.com\/xmt1139057136\/xttblog\/master\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/>--><img decoding=\"async\" src=\"https:\/\/saas.51autoparts.cn\/api\/admin\/sys-file\/oss\/file?fileName=84db51f8561e448f9a4fda2eff0811f9.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/><\/p><p>\u6700\u540e\uff0c\u6b22\u8fce\u5173\u6ce8\u6211\u7684\u4e2a\u4eba\u5fae\u4fe1\u516c\u4f17\u53f7\uff1a\u4e1a\u4f59\u8349\uff08yyucao\uff09\uff01<b>\u53ef\u52a0\u4f5c\u8005\u5fae\u4fe1\u53f7\uff1a<font color=\"red\">xttblog2<\/font>\u3002\u5907\u6ce8\uff1a\u201c1\u201d\uff0c\u6dfb\u52a0\u535a\u4e3b\u5fae\u4fe1\u62c9\u4f60\u8fdb\u5fae\u4fe1\u7fa4\u3002\u5907\u6ce8\u9519\u8bef\u4e0d\u4f1a\u540c\u610f\u597d\u53cb\u7533\u8bf7\u3002<\/b>\u518d\u6b21\u611f\u8c22\u60a8\u7684\u5173\u6ce8\uff01\u540e\u7eed\u6709\u7cbe\u5f69\u5185\u5bb9\u4f1a\u7b2c\u4e00\u65f6\u95f4\u53d1\u7ed9\u60a8\uff01\u539f\u521b\u6587\u7ae0\u6295\u7a3f\u8bf7\u53d1\u9001\u81f3532009913@qq.com\u90ae\u7bb1\u3002\u5546\u52a1\u5408\u4f5c\u4e5f\u53ef\u6dfb\u52a0\u4f5c\u8005\u5fae\u4fe1\u8fdb\u884c\u8054\u7cfb\uff01<\/p><p>\u672c\u6587\u539f\u6587\u51fa\u5904\uff1a<a href=\"https:\/\/www.xttblog.com\">\u4e1a\u4f59\u8349<\/a>\uff1a &raquo; <a href=\"https:\/\/www.xttblog.com\/?p=3815\">\u6cea\u5954\uff0c\u540c\u4e8b\u6267\u884c update \u8bed\u53e5\u6ca1\u6709\u6dfb\u52a0 where \u6761\u4ef6\uff01<\/a><\/p><!-- <div class=\"bd-reward-stl\"><button id=\"bdRewardBtn\"><span><\/span><\/button><\/div> -->","protected":false},"excerpt":{"rendered":"<p>\u8fc7\u5e74\u4e5f\u4e0d\u80fd\u5b89\u7a33\u554a\uff0c\u6700\u8fd1\u51e0\u5929\u5927\u5bb6\u90fd\u6ca1\u5fc3\u5de5\u4f5c\u4e86\uff0c\u5de5\u4f5c\u91cf\u4e5f\u5c11\u3002\u4f46\u662f\u4e00\u4e9b\u540c\u4e8b\u9ad8\u5174\u8fc7\u5ea6\u4e86\uff0c\u6267\u884c update \u8bed\u53e5\u7adf\u7136\u6ca1 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[1911,1910,83,580,393],"class_list":["post-3815","post","type-post","status-publish","format-standard","hentry","category-sql","tag-binglog","tag-binlog2sql","tag-mysql","tag-mysql----dba"],"_links":{"self":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/3815","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3815"}],"version-history":[{"count":1,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/3815\/revisions"}],"predecessor-version":[{"id":3816,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/3815\/revisions\/3816"}],"wp:attachment":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3815"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3815"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3815"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}