{"id":318,"date":"2024-12-19T13:37:17","date_gmt":"2024-12-19T05:37:17","guid":{"rendered":"https:\/\/blessingcr.com\/?p=318"},"modified":"2024-12-19T13:37:17","modified_gmt":"2024-12-19T05:37:17","slug":"%e6%95%b0%e6%8d%ae%e5%ba%93%e5%89%8d%e8%bf%9b%e5%9b%9e%e9%80%80%e6%96%b9%e6%a1%88","status":"publish","type":"post","link":"https:\/\/blessingcr.com\/?p=318","title":{"rendered":"\u6570\u636e\u5e93\u524d\u8fdb\u56de\u9000\u65b9\u6848"},"content":{"rendered":"<p>\u4e00\uff1a\u57fa\u7840\u8981\u6c42<\/p>\n<ol>\n<li>DDL \u5206\u4e24\u90e8\u5206\uff0c\u7b2c\u4e00\u90e8\u5206\u4e3a\u5f00\u53d1\u8fc7\u7a0b\u4e2d\u65b0\u589e\u7684\u5b57\u6bb5\u548c\u8868\uff08\u4e0d\u5141\u8bb8\u6709\u5220\u9664\u548c\u4fee\u6539\u64cd\u4f5c\uff09\uff1b\u7b2c\u4e8c\u90e8\u5206\u4e3a\u9700\u8981\u5220\u9664\u7684\u5b57\u6bb5\u548c\u8868\uff08\u4e0d\u5141\u8bb8\u6709\u65b0\u589e\u548c\u4fee\u6539\u64cd\u4f5c\uff09\uff1b\u5982\u679c\u6709\u6d89\u53ca\u4fee\u6539\u7684DDL\uff0c\u9700\u8981\u5206\u5f00\u4e3a\u65b0\u589e\u548c\u5220\u9664\uff1b<\/li>\n<li>DML \u4e0d\u5141\u8bb8DROP \u548c TRUNCATE; \u5982\u6709\u9700\u8981\uff0c\u8bf7\u4f7f\u7528DELETE\uff1b<\/li>\n<\/ol>\n<p>\u4e8c\uff1a\u6574\u4f53\u6d41\u7a0b<\/p>\n<ol>\n<li>\u9884\u5148\u51c6\u5907\uff1acentos 7\u673a\u5668\uff0c my2sql\uff0c2\u53f0mysql\u6570\u636e\u5e93\u5747\u9700\u8981root\u6743\u9650\uff0c mysqlbench\uff1b<br \/>\n\u6682\u65f6\u65e0\u6cd5\u5728\u98de\u4e66\u6587\u6863\u5916\u5c55\u793a\u6b64\u5185\u5bb9<\/li>\n<li>\u6570\u636e\u5e93\u6267\u884cDDL\u7b2c\u4e00\u90e8\u5206\uff1b\u524d\u8fdb\u6570\u636e\u5e93\u7ed3\u6784\uff1b<\/li>\n<li>\u4f7f\u7528mysqlbench \u6570\u636e\u5e93\u6bd4\u5bf9\uff0c\u83b7\u53d6DDL\u7b2c\u4e00\u90e8\u5206\u540e\u9000\u811a\u672c\u4fdd\u5b58\uff1b\n<ol>\n<li>\u5728mysql model\u4e0b\uff0c\u9009\u62e9database\uff0c sync with any source<\/li>\n<li>(\u53ef\u9009)\u6ca1\u6709mysql model \u7a97\u53e3\uff0c\u6253\u5f00\u968f\u4fbf\u4e00\u4e2a\u6570\u636e\u5e93\uff0c\u9009\u62e9\u5907\u4efd\u6570\u636e\u5e93<\/li>\n<\/ol>\n<\/li>\n<li>\u8bb0\u5f55\u5f53\u524d\u65f6\u95f4\uff0c\u524d\u8fdbDML\uff1b<\/li>\n<li>\u5728centos 7 \u673a\u5668\u4e0a\uff0c\u4f7f\u7528my2sql\u751f\u6210\u56de\u9000\u811a\u672c\uff1b\u547d\u4ee4\u53c2\u8003\u5982\u4e0b; \u5404\u53c2\u6570\u610f\u4e49\u53c2\u8003https:\/\/github.com\/liuhr\/my2sql<br \/>\n.\/my2sql  -user root -password xxxxx -host 192.168.3.25   -port 30306 -mode file -local-binlog-file .\/test-begin\/binlog.000001  -work-type rollback  -start-file .\/test-begin\/binlog.000001  -start-datetime &quot;2024-12-19 10:34:00&quot; -stop-datetime &quot;2028-07-16 11:00:00&quot; -output-dir .\/tmpdir -add-extraInfo true<\/li>\n<li>\u6d4b\u8bd5\u9a8c\u8bc1\n<ol>\n<li>\u82e5\u6709\u95ee\u9898\uff1a<\/li>\n<li>\u6267\u884cDML\u56de\u9000\u811a\u672c\u56de\u9000\u6570\u636e\uff0c\u6216\u8005\u6839\u636e\u7b2c\u56db\u6b65\u65f6\u95f4\u91cd\u65b0\u751f\u6210DML\u56de\u9000\u811a\u672c\uff08\u6d4b\u8bd5\u6709\u6570\u636e\u6c61\u67d3\u60c5\u51b5\u4e0b\uff09\uff0c\u56de\u9000\u6570\u636e<\/li>\n<li>\u6267\u884cDDL\u7b2c\u4e00\u90e8\u5206\u56de\u9000\u811a\u672c<\/li>\n<li>\u82e5\u65e0\u95ee\u9898\uff1a<\/li>\n<li>\u7b2c\u4e8c\u53f0mysql\u6267\u884c\u7b2c\u4e00\u90e8\u5206DDL\u524d\u8fdb\u811a\u672c<\/li>\n<li>\u5df2\u524d\u8fdb\u7684mysql\u6267\u884cDDL\u7b2c\u4e8c\u90e8\u5206\u524d\u8fdb\u811a\u672c<\/li>\n<li>\u4f7f\u7528mysql-workbench\u751f\u6210\u7b2c\u4e8c\u90e8\u5206DDL\u56de\u9000\u811a\u672c<\/li>\n<li>\u6d4b\u8bd5\u9a8c\u8bc1\uff0c\u5982\u679c\u6709\u95ee\u9898\u4f7f\u7528DDL\u7b2c\u4e8c\u90e8\u5206\u56de\u9000\u811a\u672c\u56de\u9000\u81f3\u4e0a\u4e00\u6b65<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<p>tip\uff1a<\/p>\n<pre><code>\u9a8c\u8bc1mysql\u56de\u9000\u540e\u6570\u636e\u662f\u5426\u5b8c\u5168\u4e00\u81f4\uff0c\u5148\u5bfc\u51fa\u539f\u59cb\u548c\u56de\u9000\u540e\u7684mysql\u6570\u636e\u4e3acsv\u683c\u5f0f\uff0c\u7136\u540e\u4f7f\u7528\u4e0b\u9762python\u811a\u672c\u9a8c\u8bc1\u3002\nfrom csv_diff import load_csv, compare\nimport os\n\ndef get_all_files(directory):\n    file_names = []\n    for root, dirs, files in os.walk(directory):\n        for file in files:\n            # file_names.append(os.path.join(root, file))\n            file_names.append(file)\n    return file_names\n\ndef comp(names):\n    for i in names:\n        difference = compare(\n            load_csv(open(&amp;quot;.\\\\new\\\\&amp;quot;+i, &amp;#039;rt&amp;#039;, newline=&amp;#039;&amp;#039;, encoding=&amp;#039;utf-8&amp;#039;, errors=&amp;#039;ignore&amp;#039;)),\n            load_csv(open(&amp;quot;.\\\\old\\\\&amp;quot;+i, &amp;#039;rt&amp;#039;, newline=&amp;#039;&amp;#039;, encoding=&amp;#039;utf-8&amp;#039;, errors=&amp;#039;ignore&amp;#039;))\n        )\n        print(difference)\n\ndef comp2(names):\n    for i in names:\n\n        with open(&amp;quot;.\\\\new\\\\&amp;quot;+i, &amp;#039;rt&amp;#039;, newline=&amp;#039;&amp;#039;, encoding=&amp;#039;utf-8&amp;#039;, errors=&amp;#039;ignore&amp;#039;) as f1, open(&amp;quot;.\\\\old\\\\&amp;quot;+i, &amp;#039;rt&amp;#039;, newline=&amp;#039;&amp;#039;, encoding=&amp;#039;utf-8&amp;#039;, errors=&amp;#039;ignore&amp;#039;) as f2:\n            for line1, line2 in zip(f1, f2):\n                if line1 != line2:\n                    print(line1)\n\ndef auto_create_path(FilePath):\n    if os.path.exists(FilePath):  ##\u76ee\u5f55\u5b58\u5728\uff0c\u8fd4\u56de\u4e3a\u771f\n        print(&amp;#039;dir exists&amp;#039;)\n    else:\n        print(&amp;#039;dir not exists&amp;#039;)\n        os.makedirs(FilePath)\n\nauto_create_path(&amp;quot;.\\\\new&amp;quot;)\nauto_create_path(&amp;quot;.\\\\old2&amp;quot;)\ndirectory = &amp;#039;.\\\\new&amp;#039; # \u66ff\u6362\u4e3a\u4f60\u7684\u76ee\u5f55\u8def\u5f84\nfile_names = get_all_files(directory)\ncomp2(file_names)\n\nprint(file_names)<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\uff1a\u57fa\u7840\u8981\u6c42 DDL \u5206\u4e24\u90e8\u5206\uff0c\u7b2c\u4e00\u90e8\u5206\u4e3a\u5f00\u53d1\u8fc7\u7a0b\u4e2d\u65b0\u589e\u7684\u5b57\u6bb5\u548c\u8868\uff08\u4e0d\u5141\u8bb8\u6709\u5220\u9664\u548c\u4fee\u6539\u64cd\u4f5c\uff09\uff1b\u7b2c\u4e8c\u90e8\u5206\u4e3a\u9700\u8981\u5220 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[74,24],"tags":[],"class_list":["post-318","post","type-post","status-publish","format-standard","hentry","category-74","category-24"],"_links":{"self":[{"href":"https:\/\/blessingcr.com\/index.php?rest_route=\/wp\/v2\/posts\/318","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blessingcr.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blessingcr.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blessingcr.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blessingcr.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=318"}],"version-history":[{"count":1,"href":"https:\/\/blessingcr.com\/index.php?rest_route=\/wp\/v2\/posts\/318\/revisions"}],"predecessor-version":[{"id":320,"href":"https:\/\/blessingcr.com\/index.php?rest_route=\/wp\/v2\/posts\/318\/revisions\/320"}],"wp:attachment":[{"href":"https:\/\/blessingcr.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=318"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blessingcr.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=318"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blessingcr.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=318"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}