{"id":199690,"date":"2025-05-06T08:21:28","date_gmt":"2025-05-06T00:21:28","guid":{"rendered":"https:\/\/server.hk\/cnblog\/199690\/"},"modified":"2025-05-06T08:21:28","modified_gmt":"2025-05-06T00:21:28","slug":"%e6%9c%89%e5%93%aa%e4%ba%9b%e6%96%b9%e6%b3%95%e5%8f%af%e4%bb%a5%e8%bf%81%e7%a7%bbmysql%e6%95%b0%e6%8d%ae%e5%ba%93","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/199690\/","title":{"rendered":"\u6709\u54ea\u4e9b\u65b9\u6cd5\u53ef\u4ee5\u8fc1\u79fbMySQL\u6570\u636e\u5e93"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>\u6709\u54ea\u4e9b\u65b9\u6cd5\u53ef\u4ee5\u8fc1\u79fbMySQL\u6570\u636e\u5e93<\/h1>\n<p>\u4e00\u5206\u8015\u8018\uff0c\u4e00\u5206\u6536\u83b7\uff01\u65e2\u7136\u6253\u5f00\u4e86\u8fd9\u7bc7\u6587\u7ae0\uff0c\u5c31\u575a\u6301\u770b\u4e0b\u53bb\u5427\uff01\u6587\u4e2d\u5185\u5bb9\u5305\u542b\u7b49\u7b49\u77e5\u8bc6\u70b9&#8230;\u5e0c\u671b\u4f60\u80fd\u5728\u9605\u8bfb\u672c\u6587\u540e\uff0c\u80fd\u771f\u771f\u5b9e\u5b9e\u5b66\u5230\u77e5\u8bc6\u6216\u8005\u5e2e\u4f60\u89e3\u51b3\u5fc3\u4e2d\u7684\u7591\u60d1\uff0c\u4e5f\u6b22\u8fce\u5927\u4f6c\u6216\u8005\u65b0\u4eba\u670b\u53cb\u4eec\u591a\u7559\u8a00\u8bc4\u8bba\uff0c\u591a\u7ed9\u5efa\u8bae\uff01\u8c22\u8c22\uff01<\/p>\n<p>MySQL\u6570\u636e\u5e93\u8fc1\u79fb\u7684\u65b9\u6cd5\u5305\u62ec\u4ee5\u4e0b\u51e0\u79cd\uff0c\u5176\u4e2d\u8fd8\u9644\u6709\u5177\u4f53\u4ee3\u7801\u793a\u4f8b\uff1a<\/p>\n<ol>\n<li>\u6570\u636e\u5e93\u5907\u4efd\u548c\u6062\u590d<br \/>\u6570\u636e\u5e93\u5907\u4efd\u548c\u6062\u590d\u662f\u6700\u5e38\u89c1\u7684\u8fc1\u79fb\u65b9\u6cd5\u4e4b\u4e00\u3002\u9996\u5148\uff0c\u9700\u8981\u5c06\u539f\u6570\u636e\u5e93\u5907\u4efd\u5230\u4e00\u4e2a\u6587\u4ef6\uff0c\u7136\u540e\u5c06\u5907\u4efd\u6587\u4ef6\u5bfc\u5165\u5230\u65b0\u7684\u6570\u636e\u5e93\u4e2d\u3002<\/li>\n<\/ol>\n<p>\u5907\u4efd\u6570\u636e\u5e93\u7684\u547d\u4ee4\u5982\u4e0b\uff1a<\/p>\n<pre>mysqldump -u \u7528\u6237\u540d -p \u5bc6\u7801 \u6570\u636e\u5e93\u540d &gt; \u5907\u4efd\u6587\u4ef6\u8def\u5f84<\/pre>\n<p>\u6062\u590d\u6570\u636e\u5e93\u7684\u547d\u4ee4\u5982\u4e0b\uff1a<\/p>\n<pre>mysql -u \u7528\u6237\u540d -p \u5bc6\u7801 \u65b0\u6570\u636e\u5e93\u540d &lt; \u5907\u4efd\u6587\u4ef6\u8def\u5f84<\/pre>\n<p>\u4f8b\u5982\uff0c\u8981\u5907\u4efd\u540d\u4e3a&#8221;old_db&#8221;\u7684\u6570\u636e\u5e93\u5230\u6587\u4ef6&#8221;old_db_backup.sql&#8221;\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre>mysqldump -u root -p password old_db &gt; ~\/old_db_backup.sql<\/pre>\n<p>\u8981\u5c06\u5907\u4efd\u6587\u4ef6&#8221;old_db_backup.sql&#8221;\u5bfc\u5165\u5230\u65b0\u7684\u6570\u636e\u5e93&#8221;new_db&#8221;\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre>mysql -u root -p password new_db &lt; ~\/old_db_backup.sql<\/pre>\n<ol>\n<li>\u6570\u636e\u5e93\u590d\u5236<br \/>\u6570\u636e\u5e93\u590d\u5236\u662f\u4e00\u79cd\u5c06\u539f\u6570\u636e\u5e93\u590d\u5236\u5230\u65b0\u7684\u6570\u636e\u5e93\u670d\u52a1\u5668\u7684\u65b9\u6cd5\u3002\u4f7f\u7528\u6570\u636e\u5e93\u590d\u5236\uff0c\u4e0d\u9700\u8981\u505c\u673a\u6216\u65ad\u5f00\u6570\u636e\u5e93\u670d\u52a1\u5c31\u53ef\u4ee5\u5b8c\u6210\u8fc1\u79fb\u3002<\/li>\n<\/ol>\n<p>\u9996\u5148\uff0c\u5728\u539f\u6570\u636e\u5e93\u670d\u52a1\u5668\u4e0a\u542f\u7528\u4e3b\u670d\u52a1\u5668\u65e5\u5fd7\u3002\u6253\u5f00MySQL\u914d\u7f6e\u6587\u4ef6\uff0c\u627e\u5230&#8221;[mysqld]&#8221;\u90e8\u5206\u5e76\u6dfb\u52a0\u4ee5\u4e0b\u884c\uff1a<\/p>\n<pre>log-bin=mysql-bin\nserver-id=1<\/pre>\n<p>\u7136\u540e\uff0c\u91cd\u542fMySQL\u670d\u52a1\u3002<\/p>\n<p>\u5728\u65b0\u7684\u6570\u636e\u5e93\u670d\u52a1\u5668\u4e0a\uff0c\u521b\u5efa\u4e00\u4e2a\u4e0e\u539f\u6570\u636e\u5e93\u76f8\u540c\u540d\u79f0\u7684\u7a7a\u6570\u636e\u5e93\u3002<\/p>\n<p>\u63a5\u4e0b\u6765\uff0c\u5728\u65b0\u7684\u6570\u636e\u5e93\u670d\u52a1\u5668\u4e0a\uff0c\u6253\u5f00MySQL\u914d\u7f6e\u6587\u4ef6\uff0c\u627e\u5230&#8221;[mysqld]&#8221;\u90e8\u5206\u5e76\u6dfb\u52a0\u4ee5\u4e0b\u884c\uff1a<\/p>\n<pre>relay-log=mysql-relay-bin\nserver-id=2<\/pre>\n<p>\u91cd\u542fMySQL\u670d\u52a1\u3002<\/p>\n<p>\u5728\u65b0\u7684\u6570\u636e\u5e93\u670d\u52a1\u5668\u4e0a\u767b\u5f55MySQL\uff0c\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\uff0c\u5c06\u539f\u6570\u636e\u5e93\u670d\u52a1\u5668\u4f5c\u4e3a\u4e3b\u670d\u52a1\u5668\u6dfb\u52a0\u5230\u65b0\u6570\u636e\u5e93\u670d\u52a1\u5668\u4e2d\uff1a<\/p>\n<pre>CHANGE MASTER TO\n    MASTER_HOST='\u539f\u6570\u636e\u5e93\u670d\u52a1\u5668IP\u5730\u5740',\n    MASTER_USER='\u4e3b\u670d\u52a1\u5668\u7528\u6237\u540d',\n    MASTER_PASSWORD='\u4e3b\u670d\u52a1\u5668\u5bc6\u7801',\n    MASTER_LOG_FILE='\u539f\u6570\u636e\u5e93\u670d\u52a1\u5668\u65e5\u5fd7\u6587\u4ef6',\n    MASTER_LOG_POS=\u539f\u6570\u636e\u5e93\u670d\u52a1\u5668\u65e5\u5fd7\u4f4d\u7f6e\uff1b<\/pre>\n<p>\u7136\u540e\u542f\u52a8\u590d\u5236\uff1a<\/p>\n<pre>START SLAVE;<\/pre>\n<ol>\n<li>\u6570\u636e\u5e93\u5bfc\u51fa\u548c\u5bfc\u5165<br \/>\u6570\u636e\u5e93\u5bfc\u51fa\u548c\u5bfc\u5165\u662f\u5c06\u539f\u6570\u636e\u5e93\u5bfc\u51fa\u4e3aSQL\u6587\u4ef6\uff0c\u7136\u540e\u5728\u65b0\u7684\u6570\u636e\u5e93\u4e2d\u5bfc\u5165\u8be5SQL\u6587\u4ef6\u7684\u65b9\u6cd5\u3002<\/li>\n<\/ol>\n<p>\u5bfc\u51fa\u539f\u6570\u636e\u5e93\u7684\u547d\u4ee4\u5982\u4e0b\uff1a<\/p>\n<pre>mysqldump -u \u7528\u6237\u540d -p \u5bc6\u7801 \u6570\u636e\u5e93\u540d &gt; \u5bfc\u51fa\u6587\u4ef6\u8def\u5f84<\/pre>\n<p>\u4f8b\u5982\uff0c\u8981\u5bfc\u51fa\u540d\u4e3a&#8221;old_db&#8221;\u7684\u6570\u636e\u5e93\u5230\u6587\u4ef6&#8221;old_db_export.sql&#8221;\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre>mysqldump -u root -p password old_db &gt; ~\/old_db_export.sql<\/pre>\n<p>\u5bfc\u5165SQL\u6587\u4ef6\u5230\u65b0\u7684\u6570\u636e\u5e93\u7684\u547d\u4ee4\u5982\u4e0b\uff1a<\/p>\n<pre>mysql -u \u7528\u6237\u540d -p \u5bc6\u7801 \u65b0\u6570\u636e\u5e93\u540d &lt; \u5bfc\u51fa\u6587\u4ef6\u8def\u5f84<\/pre>\n<p>\u4f8b\u5982\uff0c\u8981\u5c06SQL\u6587\u4ef6&#8221;old_db_export.sql&#8221;\u5bfc\u5165\u5230\u65b0\u7684\u6570\u636e\u5e93&#8221;new_db&#8221;\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre>mysql -u root -p password new_db &lt; ~\/old_db_export.sql<\/pre>\n<p>\u4ee5\u4e0a\u5c31\u662fMySQL\u6570\u636e\u5e93\u8fc1\u79fb\u7684\u51e0\u79cd\u5e38\u89c1\u65b9\u6cd5\uff0c\u6bcf\u79cd\u65b9\u6cd5\u90fd\u6709\u5176\u9002\u7528\u7684\u573a\u666f\uff0c\u6839\u636e\u5b9e\u9645\u60c5\u51b5\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\u8fdb\u884c\u6570\u636e\u5e93\u8fc1\u79fb\u3002<\/p>\n<p>\u597d\u4e86\uff0c\u672c\u6587\u5230\u6b64\u7ed3\u675f\uff0c\u5e26\u5927\u5bb6\u4e86\u89e3\u4e86\u300a\u6709\u54ea\u4e9b\u65b9\u6cd5\u53ef\u4ee5\u8fc1\u79fbMySQL\u6570\u636e\u5e93\u300b\uff0c\u5e0c\u671b\u672c\u6587\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff01\u5173\u6ce8\u4e3b\u673a\u5b9d\u8d1d\u516c\u4f17\u53f7\uff0c\u7ed9\u5927\u5bb6\u5206\u4eab\u66f4\u591a\u6570\u636e\u5e93\u77e5\u8bc6\uff01<\/p>\n<dl>\n<dt>\n <\/dt>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>\u6709\u54ea\u4e9b\u65b9\u6cd5\u53ef\u4ee5\u8fc1\u79fbMySQL\u6570\u636e&#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-199690","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/199690","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=199690"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/199690\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=199690"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=199690"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=199690"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}