{"id":168569,"date":"2024-11-06T13:28:20","date_gmt":"2024-11-06T05:28:20","guid":{"rendered":"https:\/\/server.hk\/cnblog\/168569\/"},"modified":"2024-11-06T13:28:21","modified_gmt":"2024-11-06T05:28:21","slug":"ssh-%e5%8a%a0%e5%af%86-mysql-%e8%a4%87%e8%a3%bd%e7%9a%84%e6%ad%a3%e7%a2%ba%e5%bb%ba%e5%88%b6","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/168569\/","title":{"rendered":"SSH \u52a0\u5bc6 MySQL \u8907\u88fd\u7684\u6b63\u78ba\u5efa\u5236"},"content":{"rendered":"<h1 id=\"ssh-%e5%8a%a0%e5%af%86-mysql-%e8%a4%87%e8%a3%bd%e7%9a%84%e6%ad%a3%e7%a2%ba%e5%bb%ba%e5%88%b6-ODEkzpnuBJ\">SSH \u52a0\u5bc6 MySQL \u8907\u88fd\u7684\u6b63\u78ba\u5efa\u5236<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u6578\u64da\u9a45\u52d5\u4e16\u754c\u4e2d\uff0c\u6578\u64da\u7684\u5b89\u5168\u6027\u548c\u53ef\u7528\u6027\u81f3\u95dc\u91cd\u8981\u3002MySQL \u4f5c\u70ba\u4e00\u500b\u6d41\u884c\u7684\u958b\u6e90\u6578\u64da\u5eab\u7ba1\u7406\u7cfb\u7d71\uff0c\u7d93\u5e38\u88ab\u7528\u65bc\u5404\u7a2e\u61c9\u7528\u7a0b\u5e8f\u4e2d\u3002\u7576\u9700\u8981\u5728\u591a\u500b\u4f3a\u670d\u5668\u4e4b\u9593\u8907\u88fd\u6578\u64da\u6642\uff0c\u78ba\u4fdd\u6578\u64da\u5728\u50b3\u8f38\u904e\u7a0b\u4e2d\u7684\u5b89\u5168\u6027\u8b8a\u5f97\u5c24\u70ba\u91cd\u8981\u3002\u672c\u6587\u5c07\u63a2\u8a0e\u5982\u4f55\u901a\u904e SSH \u52a0\u5bc6\u4f86\u6b63\u78ba\u5efa\u5236 MySQL \u8907\u88fd\uff0c\u4e26\u63d0\u4f9b\u5177\u9ad4\u7684\u6b65\u9a5f\u548c\u793a\u4f8b\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%af-mysql-%e8%a4%87%e8%a3%bd%ef%bc%9f-ODEkzpnuBJ\">\u4ec0\u9ebc\u662f MySQL \u8907\u88fd\uff1f<\/h2>\n<p>MySQL \u8907\u88fd\u662f\u4e00\u7a2e\u6578\u64da\u5eab\u6280\u8853\uff0c\u5141\u8a31\u5c07\u6578\u64da\u5f9e\u4e00\u500b MySQL \u4f3a\u670d\u5668\uff08\u4e3b\u4f3a\u670d\u5668\uff09\u8907\u88fd\u5230\u53e6\u4e00\u500b MySQL \u4f3a\u670d\u5668\uff08\u5f9e\u4f3a\u670d\u5668\uff09\u3002\u9019\u7a2e\u6280\u8853\u901a\u5e38\u7528\u65bc\u8ca0\u8f09\u5e73\u8861\u3001\u6578\u64da\u5099\u4efd\u548c\u9ad8\u53ef\u7528\u6027\u7b49\u5834\u666f\u3002\u8907\u88fd\u53ef\u4ee5\u662f\u540c\u6b65\u7684\u6216\u7570\u6b65\u7684\uff0c\u6839\u64da\u5177\u9ad4\u9700\u6c42\u9078\u64c7\u5408\u9069\u7684\u65b9\u5f0f\u3002<\/p>\n<h2 id=\"%e7%82%ba%e4%bb%80%e9%ba%bc%e9%9c%80%e8%a6%81-ssh-%e5%8a%a0%e5%af%86%ef%bc%9f-ODEkzpnuBJ\">\u70ba\u4ec0\u9ebc\u9700\u8981 SSH \u52a0\u5bc6\uff1f<\/h2>\n<p>\u5728\u9032\u884c MySQL \u8907\u88fd\u6642\uff0c\u6578\u64da\u5728\u7db2\u7d61\u4e2d\u50b3\u8f38\uff0c\u9019\u53ef\u80fd\u6703\u5c0e\u81f4\u6578\u64da\u88ab\u6514\u622a\u6216\u7be1\u6539\u3002\u4f7f\u7528 SSH\uff08\u5b89\u5168\u5916\u6bbc\u5354\u8b70\uff09\u52a0\u5bc6\u53ef\u4ee5\u6709\u6548\u5730\u4fdd\u8b77\u6578\u64da\u7684\u5b89\u5168\u6027\uff0c\u78ba\u4fdd\u6578\u64da\u5728\u50b3\u8f38\u904e\u7a0b\u4e2d\u4e0d\u88ab\u7b2c\u4e09\u65b9\u8a2a\u554f\u3002SSH \u63d0\u4f9b\u4e86\u4e00\u500b\u5b89\u5168\u7684\u901a\u9053\uff0c\u901a\u904e\u52a0\u5bc6\u6280\u8853\u4f86\u4fdd\u8b77\u6578\u64da\u7684\u5b8c\u6574\u6027\u548c\u6a5f\u5bc6\u6027\u3002<\/p>\n<h2 id=\"ssh-%e5%8a%a0%e5%af%86-mysql-%e8%a4%87%e8%a3%bd%e7%9a%84%e6%ad%a5%e9%a9%9f-ODEkzpnuBJ\">SSH \u52a0\u5bc6 MySQL \u8907\u88fd\u7684\u6b65\u9a5f<\/h2>\n<h3 id=\"%e6%ad%a5%e9%a9%9f-1%ef%bc%9a%e8%a8%ad%e7%bd%ae%e4%b8%bb%e4%bc%ba%e6%9c%8d%e5%99%a8-ODEkzpnuBJ\">\u6b65\u9a5f 1\uff1a\u8a2d\u7f6e\u4e3b\u4f3a\u670d\u5668<\/h3>\n<p>\u9996\u5148\uff0c\u60a8\u9700\u8981\u5728\u4e3b\u4f3a\u670d\u5668\u4e0a\u555f\u7528\u4e8c\u9032\u5236\u65e5\u8a8c\u3002\u9019\u53ef\u4ee5\u901a\u904e\u7de8\u8f2f MySQL \u914d\u7f6e\u6587\u4ef6\u4f86\u5b8c\u6210\u3002\u6253\u958b MySQL \u914d\u7f6e\u6587\u4ef6\uff08\u901a\u5e38\u4f4d\u65bc \/etc\/my.cnf \u6216 \/etc\/mysql\/my.cnf\uff09\uff0c\u4e26\u6dfb\u52a0\u4ee5\u4e0b\u884c\uff1a<\/p>\n<pre><code>[mysqld]\nlog-bin=mysql-bin\nserver-id=1\n<\/code><\/pre>\n<p>\u4fdd\u5b58\u6587\u4ef6\u4e26\u91cd\u555f MySQL \u670d\u52d9\uff1a<\/p>\n<pre><code>sudo systemctl restart mysql\n<\/code><\/pre>\n<h3 id=\"%e6%ad%a5%e9%a9%9f-2%ef%bc%9a%e8%a8%ad%e7%bd%ae%e5%be%9e%e4%bc%ba%e6%9c%8d%e5%99%a8-ODEkzpnuBJ\">\u6b65\u9a5f 2\uff1a\u8a2d\u7f6e\u5f9e\u4f3a\u670d\u5668<\/h3>\n<p>\u5728\u5f9e\u4f3a\u670d\u5668\u4e0a\uff0c\u60a8\u9700\u8981\u8a2d\u7f6e\u4e00\u500b\u552f\u4e00\u7684 server-id\uff0c\u4e26\u6307\u5b9a\u4e3b\u4f3a\u670d\u5668\u7684\u5730\u5740\u3002\u7de8\u8f2f\u5f9e\u4f3a\u670d\u5668\u7684 MySQL \u914d\u7f6e\u6587\u4ef6\uff0c\u6dfb\u52a0\u4ee5\u4e0b\u884c\uff1a<\/p>\n<pre><code>[mysqld]\nserver-id=2\n<\/code><\/pre>\n<p>\u4fdd\u5b58\u6587\u4ef6\u4e26\u91cd\u555f MySQL \u670d\u52d9\uff1a<\/p>\n<pre><code>sudo systemctl restart mysql\n<\/code><\/pre>\n<h3 id=\"%e6%ad%a5%e9%a9%9f-3%ef%bc%9a%e5%89%b5%e5%bb%ba%e8%a4%87%e8%a3%bd%e7%94%a8%e6%88%b6-ODEkzpnuBJ\">\u6b65\u9a5f 3\uff1a\u5275\u5efa\u8907\u88fd\u7528\u6236<\/h3>\n<p>\u5728\u4e3b\u4f3a\u670d\u5668\u4e0a\uff0c\u60a8\u9700\u8981\u5275\u5efa\u4e00\u500b\u7528\u65bc\u8907\u88fd\u7684 MySQL \u7528\u6236\u3002\u767b\u9304\u5230 MySQL \u4e26\u57f7\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre><code>CREATE USER 'replicator'@'%' IDENTIFIED BY 'password';\nGRANT REPLICATION SLAVE ON *.* TO 'replicator'@'%';\n<\/code><\/pre>\n<h3 id=\"%e6%ad%a5%e9%a9%9f-4%ef%bc%9a%e9%85%8d%e7%bd%ae-ssh-%e9%9a%a7%e9%81%93-ODEkzpnuBJ\">\u6b65\u9a5f 4\uff1a\u914d\u7f6e SSH \u96a7\u9053<\/h3>\n<p>\u5728\u5f9e\u4f3a\u670d\u5668\u4e0a\uff0c\u60a8\u9700\u8981\u901a\u904e SSH \u96a7\u9053\u9023\u63a5\u5230\u4e3b\u4f3a\u670d\u5668\u3002\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5275\u5efa SSH \u96a7\u9053\uff1a<\/p>\n<pre><code>ssh -L 3306:localhost:3306 user@\u4e3b\u4f3a\u670d\u5668IP\n<\/code><\/pre>\n<p>\u9019\u6a23\uff0c\u5f9e\u4f3a\u670d\u5668\u5c31\u53ef\u4ee5\u901a\u904e\u672c\u5730\u7aef\u53e3 3306 \u9023\u63a5\u5230\u4e3b\u4f3a\u670d\u5668\u7684 MySQL \u670d\u52d9\u3002<\/p>\n<h3 id=\"%e6%ad%a5%e9%a9%9f-5%ef%bc%9a%e5%95%9f%e5%8b%95%e8%a4%87%e8%a3%bd-ODEkzpnuBJ\">\u6b65\u9a5f 5\uff1a\u555f\u52d5\u8907\u88fd<\/h3>\n<p>\u6700\u5f8c\uff0c\u5728\u5f9e\u4f3a\u670d\u5668\u4e0a\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u958b\u59cb\u8907\u88fd\uff1a<\/p>\n<pre><code>CHANGE MASTER TO\nMASTER_HOST='127.0.0.1',\nMASTER_USER='replicator',\nMASTER_PASSWORD='password',\nMASTER_LOG_FILE='mysql-bin.000001',\nMASTER_LOG_POS=0;\n\nSTART SLAVE;\n<\/code><\/pre>\n<p>\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6aa2\u67e5\u8907\u88fd\u72c0\u614b\uff1a<\/p>\n<pre><code>SHOW SLAVE STATUSG\n<\/code><\/pre>\n<h2 id=\"%e7%b8%bd%e7%b5%90-ODEkzpnuBJ\">\u7e3d\u7d50<\/h2>\n<p>\u901a\u904e\u4ee5\u4e0a\u6b65\u9a5f\uff0c\u60a8\u53ef\u4ee5\u6210\u529f\u5730\u8a2d\u7f6e SSH \u52a0\u5bc6\u7684 MySQL \u8907\u88fd\uff0c\u5f9e\u800c\u78ba\u4fdd\u6578\u64da\u5728\u50b3\u8f38\u904e\u7a0b\u4e2d\u7684\u5b89\u5168\u6027\u3002\u9019\u7a2e\u65b9\u6cd5\u4e0d\u50c5\u63d0\u9ad8\u4e86\u6578\u64da\u7684\u5b89\u5168\u6027\uff0c\u9084\u80fd\u5920\u6709\u6548\u5730\u5be6\u73fe\u6578\u64da\u7684\u9ad8\u53ef\u7528\u6027\u548c\u8ca0\u8f09\u5e73\u8861\u3002\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u53ef\u9760\u7684 <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u89e3\u6c7a\u65b9\u6848\uff0cServer.HK \u63d0\u4f9b\u591a\u7a2e\u9078\u64c7\uff0c\u6eff\u8db3\u60a8\u7684\u9700\u6c42\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e86\u89e3\u5982\u4f55\u6b63\u78ba\u5efa\u7f6e SSH \u52a0\u5bc6\u7684 MySQL \u8907\u88fd\uff0c\u78ba\u4fdd\u6578\u64da\u5b89\u5168\u8207\u9ad8\u6548\u50b3\u8f38\uff0c\u63d0\u5347\u8cc7\u6599\u5eab\u7ba1\u7406\u7684\u5b89\u5168\u6027\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-168569","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/168569","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=168569"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/168569\/revisions"}],"predecessor-version":[{"id":168570,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/168569\/revisions\/168570"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=168569"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=168569"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=168569"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}