{"id":5288,"date":"2024-11-14T11:49:19","date_gmt":"2024-11-14T03:49:19","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5288\/"},"modified":"2024-11-14T11:49:19","modified_gmt":"2024-11-14T03:49:19","slug":"%e6%80%8e%e4%b9%88%e8%bf%9c%e7%a8%8b%e8%ae%bf%e9%97%aemysql","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5288\/","title":{"rendered":"\u600e\u4e48\u8fdc\u7a0b\u8bbf\u95eemysql"},"content":{"rendered":"<blockquote><p>\n  \u8fdc\u7a0b\u8bbf\u95ee mysql \u7684\u65b9\u6cd5\u6709\u591a\u79cd\uff0c\u5177\u4f53\u53d6\u51b3\u4e8e\u64cd\u4f5c\u7cfb\u7edf\u548c\u7f51\u7edc\u73af\u5883\u3002\u6b65\u9aa4\u5305\u62ec\uff1a1. \u542f\u7528\u8fdc\u7a0b\u8fde\u63a5\u5e76\u8bbe\u7f6e\u9632\u706b\u5899\u89c4\u5219\uff1b2. \u521b\u5efa\u8fdc\u7a0b\u7528\u6237\u5e76\u6388\u4e88\u6743\u9650\uff1b3. \u8fde\u63a5\u5230\u8fdc\u7a0b mysql \u670d\u52a1\u5668\uff1b4. \u4f7f\u7528 ssh \u96a7\u9053\u8fdb\u884c\u5b89\u5168\u52a0\u5bc6\u8fde\u63a5\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/26\/2024052618281162505.jpg\" class=\"aligncenter\" title=\"\u600e\u4e48\u8fdc\u7a0b\u8bbf\u95eemysql\u63d2\u56fe\" alt=\"\u600e\u4e48\u8fdc\u7a0b\u8bbf\u95eemysql\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u8fdc\u7a0b\u8bbf\u95ee MySQL<\/strong><\/p>\n<p>\u8fdc\u7a0b\u8bbf\u95ee MySQL \u7684\u65b9\u6cd5\u6709\u591a\u79cd\uff0c\u5177\u4f53\u53d6\u51b3\u4e8e\u4f60\u7684\u64cd\u4f5c\u7cfb\u7edf\u3001\u6570\u636e\u5e93\u7248\u672c\u548c\u7f51\u7edc\u73af\u5883\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u89c1\u7684\u6b65\u9aa4\uff1a<\/p>\n<p><strong>1. \u542f\u7528\u8fdc\u7a0b\u8fde\u63a5<\/strong><\/p>\n<ul>\n<li> <strong>Linux\/Unix\uff1a<\/strong>\u7f16\u8f91 \/etc\/\/my.cnf \u6587\u4ef6\uff0c\u5728 [mysqld] \u90e8\u5206\u6dfb\u52a0 bind-address = 0.0.0.0\u3002<\/li>\n<li> <strong>Windows\uff1a<\/strong>\u6253\u5f00 MySQL \u914d\u7f6e\u7ba1\u7406\u5668\uff0c\u5728 &#8220;TCP\/IP Networking&#8221; \u9009\u9879\u5361\u4e2d\uff0c\u52fe\u9009 &#8220;Enable TCP Networking&#8221; \u5e76\u8bbe\u7f6e &#8220;Port&#8221; \u4e3a 3306\u3002<\/li>\n<\/ul>\n<p><strong>2. \u8bbe\u7f6e\u9632\u706b\u5899\u89c4\u5219<\/strong><\/p>\n<ul>\n<li> <strong>Linux\/Unix\uff1a<\/strong>\u4f7f\u7528 sudo ufw allow 3306 \u547d\u4ee4\u6253\u5f00 3306 \u7aef\u53e3\u3002<\/li>\n<li> <strong>Windows\uff1a<\/strong>\u5728\u9632\u706b\u5899\u4e2d\u521b\u5efa\u4e00\u4e2a\u5141\u8bb8 3306 \u7aef\u53e3\u7684\u5165\u7ad9\u89c4\u5219\u3002<\/li>\n<\/ul>\n<p><strong>3. \u521b\u5efa\u8fdc\u7a0b\u7528\u6237<\/strong><\/p>\n<ul>\n<li>\u5728 MySQL \u547d\u4ee4\u884c\u63d0\u793a\u7b26\u4e2d\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/li>\n<\/ul>\n<pre>CREATE USER 'remote_user'@'%' IDENTIFIED BY 'password';\nGRANT ALL PRIVILEGES ON *.* TO 'remote_user'@'%';\nFLUSH PRIVILEGES;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>4. \u8fde\u63a5\u5230\u8fdc\u7a0b MySQL \u670d\u52a1\u5668<\/strong><\/p>\n<p>\u4f7f\u7528\u4ee5\u4e0b\u8bed\u6cd5\u4ece\u8fdc\u7a0b\u8ba1\u7b97\u673a\u8fde\u63a5\u5230 MySQL \u670d\u52a1\u5668\uff1a<\/p>\n<pre>mysql -u remote_user -p -h host_name<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ul>\n<li> <strong>-u\uff1a<\/strong>\u8fdc\u7a0b\u7528\u6237\u540d<\/li>\n<li> <strong>-p\uff1a<\/strong>\u63d0\u793a\u8f93\u5165\u8fdc\u7a0b\u7528\u6237\u5bc6\u7801<\/li>\n<li> <strong>-h\uff1a<\/strong>\u8fdc\u7a0b MySQL \u670d\u52a1\u5668\u7684\u4e3b\u673a\u540d\u6216 IP \u5730\u5740<\/li>\n<\/ul>\n<p><strong>5. \u4f7f\u7528 SSH \u96a7\u9053<\/strong><\/p>\n<p>SSH \u96a7\u9053\u662f\u4e00\u79cd\u5b89\u5168\u7684\u65b9\u6cd5\uff0c\u53ef\u4ee5\u901a\u8fc7\u5b89\u5168\u5957\u63a5\u5b57\u5c42 (SSL) \u52a0\u5bc6\u8fde\u63a5\u6765\u8fdc\u7a0b\u8bbf\u95ee MySQL\u3002\u8981\u4f7f\u7528 SSH \u96a7\u9053\uff1a<\/p>\n<ul>\n<li>\u5728\u8fdc\u7a0b\u8ba1\u7b97\u673a\u4e0a\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u542f\u52a8 SSH \u96a7\u9053\uff1a<\/li>\n<\/ul>\n<pre>ssh -L 3306:localhost:3306 remote_user@host_name<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ul>\n<li>\u5728\u672c\u5730\u8ba1\u7b97\u673a\u4e0a\uff0c\u4f7f\u7528\u4ee5\u4e0b\u8bed\u6cd5\u8fde\u63a5\u5230 MySQL \u670d\u52a1\u5668\uff1a<\/li>\n<\/ul>\n<pre>mysql -u remote_user -p -h 127.0.0.1<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u600e\u4e48\u8fdc\u7a0b\u8bbf\u95ee\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>\u8fdc\u7a0b\u8bbf\u95ee mysql \u7684\u65b9\u6cd5\u6709\u591a\u79cd\uff0c\u5177\u4f53\u53d6\u51b3\u4e8e\u64cd\u4f5c\u7cfb\u7edf\u548c\u7f51\u7edc\u73af\u5883\u3002\u6b65\u9aa4\u5305\u62ec\uff1a1. \u542f\u7528\u8fdc\u7a0b\u8fde\u63a5\u5e76\u8bbe\u7f6e\u9632\u706b\u5899\u89c4\u5219\uff1b2. \u521b\u5efa\u8fdc\u7a0b\u7528\u6237\u5e76\u6388\u4e88\u6743\u9650\uff1b3. \u8fde\u63a5\u5230\u8fdc\u7a0b mysql \u670d\u52a1\u5668\uff1b4. \u4f7f\u7528 ssh \u96a7\u9053\u8fdb\u884c\u5b89\u5168\u52a0\u5bc6\u8fde\u63a5\u3002 \u5982\u4f55\u8fdc\u7a0b\u8bbf\u95ee MySQL \u8fdc\u7a0b\u8bbf\u95ee MySQL \u7684\u65b9\u6cd5\u6709\u591a\u79cd\uff0c\u5177\u4f53\u53d6\u51b3\u4e8e\u4f60\u7684\u64cd\u4f5c\u7cfb\u7edf\u3001\u6570\u636e\u5e93\u7248\u672c\u548c\u7f51\u7edc\u73af\u5883\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u89c1\u7684\u6b65\u9aa4\uff1a 1. \u542f\u7528\u8fdc\u7a0b\u8fde\u63a5 Linux\/Unix\uff1a\u7f16\u8f91 \/etc\/\/my.cnf \u6587\u4ef6\uff0c\u5728 [mysqld] \u90e8\u5206\u6dfb\u52a0 bind-address = 0.0.0.0\u3002 Windows\uff1a\u6253\u5f00 MySQL \u914d\u7f6e\u7ba1\u7406\u5668\uff0c\u5728 &#8220;TCP\/IP Networking&#8221; \u9009\u9879\u5361\u4e2d\uff0c\u52fe\u9009 &#8220;Enable TCP Networking&#8221; \u5e76\u8bbe\u7f6e &#8220;Port&#8221; \u4e3a 3306\u3002 2. \u8bbe\u7f6e\u9632\u706b\u5899\u89c4\u5219 Linux\/Unix\uff1a\u4f7f\u7528 sudo ufw allow 3306 \u547d\u4ee4\u6253\u5f00 3306 \u7aef\u53e3\u3002 Windows\uff1a\u5728\u9632\u706b\u5899\u4e2d\u521b\u5efa\u4e00\u4e2a\u5141\u8bb8 3306 \u7aef\u53e3\u7684\u5165\u7ad9\u89c4\u5219\u3002 3. \u521b\u5efa\u8fdc\u7a0b\u7528\u6237 \u5728 [&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-5288","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5288","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=5288"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5288\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5288"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5288"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5288"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}