{"id":5463,"date":"2024-11-14T12:50:04","date_gmt":"2024-11-14T04:50:04","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5463\/"},"modified":"2024-11-14T12:50:04","modified_gmt":"2024-11-14T04:50:04","slug":"mysql%e4%b8%bb%e4%bb%8e%e6%80%8e%e4%b9%88%e5%81%9a","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5463\/","title":{"rendered":"mysql\u4e3b\u4ece\u600e\u4e48\u505a"},"content":{"rendered":"<blockquote><p>\n  \u914d\u7f6e mysql \u4e3b\u4ece\u590d\u5236\u6d89\u53ca\u4ee5\u4e0b\u6b65\u9aa4\uff1a\u8bbe\u7f6e\u4e3b\u670d\u52a1\u5668\uff0c\u521b\u5efa\u6570\u636e\u5e93\u3001\u542f\u7528\u4e8c\u8fdb\u5236\u65e5\u5fd7\u8bb0\u5f55\u3001\u6388\u4e88\u590d\u5236\u6743\u9650\u3002\u8bbe\u7f6e\u4ece\u670d\u52a1\u5668\uff0c\u5bfc\u5165\u6570\u636e\u5e93\u3001\u7f16\u8f91\u914d\u7f6e\u6587\u4ef6\u3001\u542f\u52a8\u670d\u52a1\u3002\u542f\u52a8\u590d\u5236\uff0c\u4f7f\u7528 show master status \u548c change master to \u547d\u4ee4\u8fde\u63a5\u4e3b\u4ece\u670d\u52a1\u5668\u3002\u9a8c\u8bc1\u590d\u5236\uff0c\u4f7f\u7528 show slave status \u547d\u4ee4\u68c0\u67e5 slave_io_running \u548c slave_sql_running \u662f\u5426\u4e3a yes\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/28\/2024052815154136816.jpg\" class=\"aligncenter\" title=\"mysql\u4e3b\u4ece\u600e\u4e48\u505a\u63d2\u56fe\" alt=\"mysql\u4e3b\u4ece\u600e\u4e48\u505a\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u914d\u7f6e MySQL \u4e3b\u4ece\u590d\u5236<\/strong><\/p>\n<p><strong>\u6b65\u9aa4 1\uff1a\u8bbe\u7f6e\u4e3b\u670d\u52a1\u5668<\/strong><\/p>\n<ol>\n<li>\u521b\u5efa\u4e00\u4e2a\u5305\u542b\u5f85\u590d\u5236\u6570\u636e\u7684 MySQL \u6570\u636e\u5e93\u5b9e\u4f8b\u3002<\/li>\n<li>\n<p>\u542f\u7528\u4e8c\u8fdb\u5236\u65e5\u5fd7\u8bb0\u5f55\uff08binlog\uff09\u3002\u4e3a\u6b64\uff0c\u8bf7\u7f16\u8f91 my.cnf \u914d\u7f6e\u6587\u4ef6\u5e76\u6dfb\u52a0\u4ee5\u4e0b\u884c\uff1a<\/p>\n<pre>[mysqld]\nlog-bin=&lt;log_file_name&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<li>\n<p>\u6388\u4e88\u590d\u5236\u7528\u6237\u6743\u9650\uff1a<\/p>\n<pre>GRANT REPLICATION SLAVE ON *.* TO 'username'@'hostname' IDENTIFIED BY 'password';<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<\/ol>\n<p><strong>\u6b65\u9aa4 2\uff1a\u8bbe\u7f6e\u4ece\u670d\u52a1\u5668<\/strong><\/p>\n<ol>\n<li>\u521b\u5efa\u4e00\u4e2a\u65b0\u7684 MySQL \u6570\u636e\u5e93\u5b9e\u4f8b\u3002<\/li>\n<li>\u4ece\u4e3b\u670d\u52a1\u5668\u5bfc\u5165\u6570\u636e\u5e93\u6a21\u5f0f\u548c\u6570\u636e\u3002<\/li>\n<li>\u505c\u6b62\u4ece\u670d\u52a1\u5668\u4e0a\u7684 MySQL \u670d\u52a1\u3002<\/li>\n<li>\n<p>\u7f16\u8f91 my.cnf \u914d\u7f6e\u6587\u4ef6\u5e76\u6dfb\u52a0\u4ee5\u4e0b\u884c\uff1a<\/p>\n<pre>[mysqld]\nserver-id=&lt;unique_id&gt;\nreplicate-do-db=&lt;database_name_1&gt;,&lt;database_name_2&gt;,...\nreplicate-ignore-db=&lt;database_name_1&gt;,&lt;database_name_2&gt;,...<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<li>\u542f\u52a8\u4ece\u670d\u52a1\u5668\u4e0a\u7684 MySQL \u670d\u52a1\u3002<\/li>\n<\/ol>\n<p><strong>\u6b65\u9aa4 3\uff1a\u542f\u52a8\u590d\u5236<\/strong><\/p>\n<ol>\n<li>\n<p>\u8fde\u63a5\u5230\u4e3b\u670d\u52a1\u5668\u5e76\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre>SHOW MASTER STATUS;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<li>\u8f93\u51fa\u5c06\u663e\u793a\u4e3b\u670d\u52a1\u5668\u7684\u4e8c\u8fdb\u5236\u65e5\u5fd7\u6587\u4ef6\u540d\u79f0\u548c\u4f4d\u7f6e\u3002<\/li>\n<li>\n<p>\u8fde\u63a5\u5230\u4ece\u670d\u52a1\u5668\u5e76\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre>CHANGE MASTER TO MASTER_HOST='&lt;master_hostname&gt;', MASTER_USER='&lt;master_username&gt;', MASTER_PASSWORD='&lt;master_password&gt;', MASTER_LOG_FILE='&lt;master_log_file_name&gt;', MASTER_LOG_POS=&lt;master_log_pos&gt;;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<\/ol>\n<p><strong>\u6b65\u9aa4 4\uff1a\u9a8c\u8bc1\u590d\u5236<\/strong><\/p>\n<ol>\n<li>\n<p>\u5728\u4ece\u670d\u52a1\u5668\u4e0a\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre>SHOW SLAVE STATUS;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<li>\u8f93\u51fa\u5e94\u663e\u793a Slave_IO_Running \u548c Slave_SQL_Running \u4e3a Yes\u3002<\/li>\n<\/ol>\n<p>\u4ee5\u4e0a\u5c31\u662f\u4e3b\u4ece\u600e\u4e48\u505a\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u7f51\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u914d\u7f6e mysql \u4e3b\u4ece\u590d\u5236\u6d89\u53ca\u4ee5\u4e0b\u6b65\u9aa4\uff1a\u8bbe\u7f6e\u4e3b\u670d\u52a1\u5668\uff0c\u521b\u5efa\u6570\u636e\u5e93\u3001\u542f\u7528\u4e8c\u8fdb\u5236\u65e5\u5fd7\u8bb0\u5f55\u3001\u6388\u4e88\u590d\u5236\u6743\u9650\u3002\u8bbe\u7f6e\u4ece\u670d\u52a1\u5668\uff0c\u5bfc\u5165\u6570\u636e\u5e93\u3001\u7f16\u8f91\u914d\u7f6e\u6587\u4ef6\u3001\u542f\u52a8\u670d\u52a1\u3002\u542f\u52a8\u590d\u5236\uff0c\u4f7f\u7528 show master status \u548c change master to \u547d\u4ee4\u8fde\u63a5\u4e3b\u4ece\u670d\u52a1\u5668\u3002\u9a8c\u8bc1\u590d\u5236\uff0c\u4f7f\u7528 show slave status \u547d\u4ee4\u68c0\u67e5 slave_io_running \u548c slave_sql_running \u662f\u5426\u4e3a yes\u3002 \u5982\u4f55\u914d\u7f6e MySQL \u4e3b\u4ece\u590d\u5236 \u6b65\u9aa4 1\uff1a\u8bbe\u7f6e\u4e3b\u670d\u52a1\u5668 \u521b\u5efa\u4e00\u4e2a\u5305\u542b\u5f85\u590d\u5236\u6570\u636e\u7684 MySQL \u6570\u636e\u5e93\u5b9e\u4f8b\u3002 \u542f\u7528\u4e8c\u8fdb\u5236\u65e5\u5fd7\u8bb0\u5f55\uff08binlog\uff09\u3002\u4e3a\u6b64\uff0c\u8bf7\u7f16\u8f91 my.cnf \u914d\u7f6e\u6587\u4ef6\u5e76\u6dfb\u52a0\u4ee5\u4e0b\u884c\uff1a [mysqld] log-bin=&lt;log_file_name&gt; \u767b\u5f55\u540e\u590d\u5236 \u6388\u4e88\u590d\u5236\u7528\u6237\u6743\u9650\uff1a GRANT REPLICATION SLAVE ON *.* TO &#8216;username&#8217;@&#8217;hostname&#8217; IDENTIFIED BY &#8216;password&#8217;; \u767b\u5f55\u540e\u590d\u5236 \u6b65\u9aa4 2\uff1a\u8bbe\u7f6e\u4ece\u670d\u52a1\u5668 \u521b\u5efa\u4e00\u4e2a\u65b0\u7684 MySQL \u6570\u636e\u5e93\u5b9e\u4f8b\u3002 \u4ece\u4e3b\u670d\u52a1\u5668\u5bfc\u5165\u6570\u636e\u5e93\u6a21\u5f0f\u548c\u6570\u636e\u3002 \u505c\u6b62\u4ece\u670d\u52a1\u5668\u4e0a\u7684 MySQL \u670d\u52a1\u3002 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-5463","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5463","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=5463"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5463\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5463"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5463"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5463"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}