{"id":76680,"date":"2024-10-16T08:55:18","date_gmt":"2024-10-16T00:55:18","guid":{"rendered":"https:\/\/server.hk\/cnblog\/76680\/"},"modified":"2024-10-16T08:55:18","modified_gmt":"2024-10-16T00:55:18","slug":"mysql%e6%95%b8%e6%93%9a%e5%ba%ab%e5%9c%a8%e4%b8%bb%e6%b5%81%e6%93%8d%e4%bd%9c%e7%b3%bb%e7%b5%b1%e4%b8%8b%e7%9a%84%e5%90%8c%e6%ad%a5","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/76680\/","title":{"rendered":"MySQL\u6578\u64da\u5eab\u5728\u4e3b\u6d41\u64cd\u4f5c\u7cfb\u7d71\u4e0b\u7684\u540c\u6b65"},"content":{"rendered":"<h1 id=\"mysql%e6%95%b8%e6%93%9a%e5%ba%ab%e5%9c%a8%e4%b8%bb%e6%b5%81%e6%93%8d%e4%bd%9c%e7%b3%bb%e7%b5%b1%e4%b8%8b%e7%9a%84%e5%90%8c%e6%ad%a5-dgfkLlhwWf\">MySQL\u6578\u64da\u5eab\u5728\u4e3b\u6d41\u64cd\u4f5c\u7cfb\u7d71\u4e0b\u7684\u540c\u6b65<\/h1>\n<p>MySQL\u662f\u4e00\u500b\u5ee3\u6cdb\u4f7f\u7528\u7684\u958b\u6e90\u95dc\u806f\u6578\u64da\u5eab\u7ba1\u7406\u7cfb\u7d71\uff0c\u56e0\u5176\u9ad8\u6548\u80fd\u548c\u9748\u6d3b\u6027\u800c\u53d7\u5230\u958b\u767c\u8005\u7684\u9752\u775e\u3002\u5728\u591a\u500b\u64cd\u4f5c\u7cfb\u7d71\u4e0a\u904b\u884cMySQL\u6642\uff0c\u6578\u64da\u5eab\u7684\u540c\u6b65\u6210\u70ba\u4e00\u500b\u91cd\u8981\u7684\u8ab2\u984c\u3002\u672c\u6587\u5c07\u63a2\u8a0e\u5728\u4e3b\u6d41\u64cd\u4f5c\u7cfb\u7d71\uff08\u5982Linux\u3001Windows\u548cmacOS\uff09\u4e0b\uff0cMySQL\u6578\u64da\u5eab\u7684\u540c\u6b65\u65b9\u6cd5\u53ca\u5176\u5be6\u73fe\u65b9\u5f0f\u3002<\/p>\n<h2 id=\"mysql%e6%95%b8%e6%93%9a%e5%ba%ab%e5%90%8c%e6%ad%a5%e7%9a%84%e5%9f%ba%e6%9c%ac%e6%a6%82%e5%bf%b5-dgfkLlhwWf\">MySQL\u6578\u64da\u5eab\u540c\u6b65\u7684\u57fa\u672c\u6982\u5ff5<\/h2>\n<p>\u6578\u64da\u5eab\u540c\u6b65\u662f\u6307\u5c07\u6578\u64da\u5f9e\u4e00\u500b\u6578\u64da\u5eab\u5be6\u4f8b\u8907\u88fd\u5230\u53e6\u4e00\u500b\u5be6\u4f8b\u7684\u904e\u7a0b\u3002\u9019\u4e00\u904e\u7a0b\u53ef\u4ee5\u662f\u55ae\u5411\u7684\uff08\u4e3b\u5f9e\u540c\u6b65\uff09\u6216\u96d9\u5411\u7684\uff08\u96d9\u4e3b\u540c\u6b65\uff09\u3002\u5728MySQL\u4e2d\uff0c\u4e3b\u5f9e\u540c\u6b65\u662f\u6700\u5e38\u898b\u7684\u6a21\u5f0f\uff0c\u901a\u5e38\u7528\u65bc\u6578\u64da\u5099\u4efd\u548c\u8ca0\u8f09\u5747\u8861\u3002<\/p>\n<h2 id=\"%e5%9c%a8linux%e7%b3%bb%e7%b5%b1%e4%b8%8b%e7%9a%84mysql%e5%90%8c%e6%ad%a5-dgfkLlhwWf\">\u5728Linux\u7cfb\u7d71\u4e0b\u7684MySQL\u540c\u6b65<\/h2>\n<p>Linux\u662fMySQL\u6700\u5e38\u7528\u7684\u64cd\u4f5c\u7cfb\u7d71\u4e4b\u4e00\uff0c\u56e0\u5176\u7a69\u5b9a\u6027\u548c\u9ad8\u6548\u80fd\u3002\u4ee5\u4e0b\u662fLinux\u4e0b\u8a2d\u7f6eMySQL\u4e3b\u5f9e\u540c\u6b65\u7684\u57fa\u672c\u6b65\u9a5f\uff1a<\/p>\n<ol>\n<li><strong>\u914d\u7f6e\u4e3b\u4f3a\u670d\u5668\uff1a<\/strong>\u5728\u4e3b\u4f3a\u670d\u5668\u7684MySQL\u914d\u7f6e\u6587\u4ef6\uff08\u901a\u5e38\u4f4d\u65bc\/etc\/my.cnf\uff09\u4e2d\uff0c\u6dfb\u52a0\u4ee5\u4e0b\u884c\uff1a<\/li>\n<pre><code>[mysqld]\nserver-id=1\nlog-bin=mysql-bin\n<\/code><\/pre>\n<li><strong>\u5275\u5efa\u8907\u88fd\u7528\u6236\uff1a<\/strong>\u5728\u4e3b\u4f3a\u670d\u5668\u4e0a\u5275\u5efa\u4e00\u500b\u7528\u65bc\u8907\u88fd\u7684\u7528\u6236\uff1a<\/li>\n<pre><code>CREATE USER 'replicator'@'%' IDENTIFIED BY 'password';\nGRANT REPLICATION SLAVE ON *.* TO 'replicator'@'%';\n<\/code><\/pre>\n<li><strong>\u914d\u7f6e\u5f9e\u4f3a\u670d\u5668\uff1a<\/strong>\u5728\u5f9e\u4f3a\u670d\u5668\u7684MySQL\u914d\u7f6e\u6587\u4ef6\u4e2d\uff0c\u6dfb\u52a0\u4ee5\u4e0b\u884c\uff1a<\/li>\n<pre><code>[mysqld]\nserver-id=2\n<\/code><\/pre>\n<li><strong>\u555f\u52d5\u5f9e\u4f3a\u670d\u5668\u7684\u8907\u88fd\uff1a<\/strong>\u5728\u5f9e\u4f3a\u670d\u5668\u4e0a\u57f7\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/li>\n<pre><code>CHANGE MASTER TO\nMASTER_HOST='\u4e3b\u4f3a\u670d\u5668IP',\nMASTER_USER='replicator',\nMASTER_PASSWORD='password',\nMASTER_LOG_FILE='mysql-bin.000001',\nMASTER_LOG_POS=0;\nSTART SLAVE;\n<\/code><\/pre>\n<\/ol>\n<h2 id=\"%e5%9c%a8windows%e7%b3%bb%e7%b5%b1%e4%b8%8b%e7%9a%84mysql%e5%90%8c%e6%ad%a5-dgfkLlhwWf\">\u5728Windows\u7cfb\u7d71\u4e0b\u7684MySQL\u540c\u6b65<\/h2>\n<p>\u5728Windows\u7cfb\u7d71\u4e0a\uff0cMySQL\u7684\u540c\u6b65\u8a2d\u7f6e\u8207Linux\u76f8\u4f3c\uff0c\u4f46\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0cWindows\u7684\u6587\u4ef6\u8def\u5f91\u548c\u670d\u52d9\u7ba1\u7406\u65b9\u5f0f\u6709\u6240\u4e0d\u540c\u3002\u4ee5\u4e0b\u662fWindows\u4e0b\u7684\u8a2d\u7f6e\u6b65\u9a5f\uff1a<\/p>\n<ol>\n<li><strong>\u914d\u7f6e\u4e3b\u4f3a\u670d\u5668\uff1a<\/strong>\u5728\u4e3b\u4f3a\u670d\u5668\u7684my.ini\u6587\u4ef6\u4e2d\uff0c\u6dfb\u52a0\u4ee5\u4e0b\u884c\uff1a<\/li>\n<pre><code>[mysqld]\nserver-id=1\nlog-bin=mysql-bin\n<\/code><\/pre>\n<li><strong>\u5275\u5efa\u8907\u88fd\u7528\u6236\uff1a<\/strong>\u8207Linux\u76f8\u540c\uff0c\u5275\u5efa\u8907\u88fd\u7528\u6236\uff1a<\/li>\n<pre><code>CREATE USER 'replicator'@'%' IDENTIFIED BY 'password';\nGRANT REPLICATION SLAVE ON *.* TO 'replicator'@'%';\n<\/code><\/pre>\n<li><strong>\u914d\u7f6e\u5f9e\u4f3a\u670d\u5668\uff1a<\/strong>\u5728\u5f9e\u4f3a\u670d\u5668\u7684my.ini\u6587\u4ef6\u4e2d\uff0c\u6dfb\u52a0\u4ee5\u4e0b\u884c\uff1a<\/li>\n<pre><code>[mysqld]\nserver-id=2\n<\/code><\/pre>\n<li><strong>\u555f\u52d5\u5f9e\u4f3a\u670d\u5668\u7684\u8907\u88fd\uff1a<\/strong>\u5728\u5f9e\u4f3a\u670d\u5668\u4e0a\u57f7\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/li>\n<pre><code>CHANGE MASTER TO\nMASTER_HOST='\u4e3b\u4f3a\u670d\u5668IP',\nMASTER_USER='replicator',\nMASTER_PASSWORD='password',\nMASTER_LOG_FILE='mysql-bin.000001',\nMASTER_LOG_POS=0;\nSTART SLAVE;\n<\/code><\/pre>\n<\/ol>\n<h2 id=\"%e5%9c%a8macos%e7%b3%bb%e7%b5%b1%e4%b8%8b%e7%9a%84mysql%e5%90%8c%e6%ad%a5-dgfkLlhwWf\">\u5728macOS\u7cfb\u7d71\u4e0b\u7684MySQL\u540c\u6b65<\/h2>\n<p>macOS\u7528\u6236\u4e5f\u53ef\u4ee5\u8f15\u9b06\u8a2d\u7f6eMySQL\u7684\u4e3b\u5f9e\u540c\u6b65\u3002\u6b65\u9a5f\u8207Linux\u76f8\u4f3c\uff0c\u4f46\u9700\u8981\u4f7f\u7528Homebrew\u6216\u5176\u4ed6\u5305\u7ba1\u7406\u5de5\u5177\u5b89\u88ddMySQL\u3002\u4ee5\u4e0b\u662fmacOS\u7684\u8a2d\u7f6e\u6b65\u9a5f\uff1a<\/p>\n<ol>\n<li><strong>\u914d\u7f6e\u4e3b\u4f3a\u670d\u5668\uff1a<\/strong>\u5728\u4e3b\u4f3a\u670d\u5668\u7684my.cnf\u6587\u4ef6\u4e2d\uff0c\u6dfb\u52a0\u4ee5\u4e0b\u884c\uff1a<\/li>\n<pre><code>[mysqld]\nserver-id=1\nlog-bin=mysql-bin\n<\/code><\/pre>\n<li><strong>\u5275\u5efa\u8907\u88fd\u7528\u6236\uff1a<\/strong>\u540c\u6a23\uff0c\u5275\u5efa\u8907\u88fd\u7528\u6236\uff1a<\/li>\n<pre><code>CREATE USER 'replicator'@'%' IDENTIFIED BY 'password';\nGRANT REPLICATION SLAVE ON *.* TO 'replicator'@'%';\n<\/code><\/pre>\n<li><strong>\u914d\u7f6e\u5f9e\u4f3a\u670d\u5668\uff1a<\/strong>\u5728\u5f9e\u4f3a\u670d\u5668\u7684my.cnf\u6587\u4ef6\u4e2d\uff0c\u6dfb\u52a0\u4ee5\u4e0b\u884c\uff1a<\/li>\n<pre><code>[mysqld]\nserver-id=2\n<\/code><\/pre>\n<li><strong>\u555f\u52d5\u5f9e\u4f3a\u670d\u5668\u7684\u8907\u88fd\uff1a<\/strong>\u5728\u5f9e\u4f3a\u670d\u5668\u4e0a\u57f7\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/li>\n<pre><code>CHANGE MASTER TO\nMASTER_HOST='\u4e3b\u4f3a\u670d\u5668IP',\nMASTER_USER='replicator',\nMASTER_PASSWORD='password',\nMASTER_LOG_FILE='mysql-bin.000001',\nMASTER_LOG_POS=0;\nSTART SLAVE;\n<\/code><\/pre>\n<\/ol>\n<h2 id=\"%e7%b8%bd%e7%b5%90-dgfkLlhwWf\">\u7e3d\u7d50<\/h2>\n<p>MySQL\u6578\u64da\u5eab\u5728\u4e0d\u540c\u64cd\u4f5c\u7cfb\u7d71\u4e0b\u7684\u540c\u6b65\u8a2d\u7f6e\u96d6\u7136\u6709\u4e9b\u8a31\u5dee\u7570\uff0c\u4f46\u57fa\u672c\u539f\u5247\u662f\u4e00\u81f4\u7684\u3002\u7121\u8ad6\u662f\u5728Linux\u3001Windows\u9084\u662fmacOS\u4e0a\uff0c\u901a\u904e\u6b63\u78ba\u7684\u914d\u7f6e\u548c\u547d\u4ee4\uff0c\u90fd\u80fd\u5be6\u73fe\u9ad8\u6548\u7684\u6578\u64da\u540c\u6b65\u3002\u5c0d\u65bc\u9700\u8981\u9ad8\u53ef\u7528\u6027\u548c\u6578\u64da\u5b89\u5168\u6027\u7684\u61c9\u7528\u4f86\u8aaa\uff0c\u638c\u63e1\u9019\u4e9b\u540c\u6b65\u6280\u8853\u662f\u81f3\u95dc\u91cd\u8981\u7684\u3002<\/p>\n<p>\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u7a69\u5b9a\u7684 <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u89e3\u6c7a\u65b9\u6848\uff0cServer.HK\u63d0\u4f9b\u591a\u7a2e\u9078\u64c7\uff0c\u6eff\u8db3\u4e0d\u540c\u9700\u6c42\u7684\u7528\u6236\u3002\u7121\u8ad6\u662f\u6578\u64da\u5eab\u7ba1\u7406\u9084\u662f\u7db2\u7ad9\u6258\u7ba1\uff0c\u6211\u5011\u7684 <a href=\"https:\/\/server.hk\">\u4f3a\u670d\u5668<\/a> \u90fd\u80fd\u70ba\u60a8\u63d0\u4f9b\u53ef\u9760\u7684\u652f\u6301\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63a2\u7d22MySQL\u6578\u64da\u5eab\u5728\u4e3b\u6d41\u64cd\u4f5c\u7cfb\u7d71\u4e0b\u7684\u540c\u6b65\u6280\u8853\uff0c\u63d0\u5347\u6578\u64da\u4e00\u81f4\u6027\u8207\u53ef\u9760\u6027\uff0c\u78ba\u4fdd\u9ad8\u6548\u904b\u884c\u3002<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-76680","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/76680","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"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=76680"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/76680\/revisions"}],"predecessor-version":[{"id":76681,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/76680\/revisions\/76681"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=76680"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=76680"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=76680"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}