{"id":63805,"date":"2025-04-29T12:26:23","date_gmt":"2025-04-29T04:26:23","guid":{"rendered":"https:\/\/fwq.ai\/blog\/63805\/"},"modified":"2025-04-29T12:26:23","modified_gmt":"2025-04-29T04:26:23","slug":"docker%e4%b8%ad%e7%9a%84mysql%e6%80%8e%e4%b9%88%e8%bf%9e%e6%8e%a5-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/63805\/","title":{"rendered":"docker\u4e2d\u7684mysql\u600e\u4e48\u8fde\u63a5"},"content":{"rendered":"<blockquote><p>\n  \u8fde\u63a5 docker \u4e2d\u7684 mysql \u6570\u636e\u5e93\u53ea\u9700\u4e94\u4e2a\u6b65\u9aa4\uff1a\u542f\u52a8 mysql \u5bb9\u5668\u3002\u67e5\u627e\u5bb9\u5668\u7684 ip \u5730\u5740\u3002\u4f7f\u7528\u5916\u90e8\u5ba2\u6237\u7aef\u8fde\u63a5\u5230 ip \u5730\u5740\u548c 3306 \u7aef\u53e3\u3002\u8f93\u5165\u542f\u52a8\u65f6\u6307\u5b9a\u7684 root \u5bc6\u7801\u3002\u6307\u5b9a\u542f\u52a8\u65f6\u6307\u5b9a\u7684\u6570\u636e\u5e93\u540d\u79f0\uff08\u5982\u679c\u9002\u7528\uff09\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202406\/05\/2024060508541914749.jpg\" class=\"aligncenter\" title=\"docker\u4e2d\u7684mysql\u600e\u4e48\u8fde\u63a5\u63d2\u56fe\" alt=\"docker\u4e2d\u7684mysql\u600e\u4e48\u8fde\u63a5\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u8fde\u63a5 Docker \u4e2d\u7684 MySQL \u6570\u636e\u5e93<\/strong><\/p>\n<p>\u8fde\u63a5 Docker \u4e2d\u7684 MySQL \u6570\u636e\u5e93\u7684\u8fc7\u7a0b\u5f88\u7b80\u5355\uff0c\u53ef\u4ee5\u5206\u4e3a\u4ee5\u4e0b\u6b65\u9aa4\uff1a<\/p>\n<p><strong>1. \u542f\u52a8 MySQL \u5bb9\u5668<\/strong><\/p>\n<pre>docker run -d --name my-mysql -e MYSQL_ROOT_PASSWORD=my-secret-password -e MYSQL_DATABASE=my-database mysql:latest<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>2. \u67e5\u627e MySQL \u5bb9\u5668\u7684 IP \u5730\u5740<\/strong><\/p>\n<pre>docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' my-mysql<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>3. \u4f7f\u7528\u5916\u90e8 MySQL \u5ba2\u6237\u7aef\u8fde\u63a5<\/strong><\/p>\n<p>\u5728\u672c\u5730\u8ba1\u7b97\u673a\u4e0a\uff0c\u4f7f\u7528\u60a8\u7684\u9996\u9009 MySQL \u5ba2\u6237\u7aef\uff08\u4f8b\u5982 MySQL Workbench \u6216  \u547d\u4ee4\u884c\u5de5\u5177\uff09\u8fde\u63a5\u5230\u5bb9\u5668\u7684 IP \u5730\u5740\u548c 3306 \u7aef\u53e3\uff08MySQL \u7684\u9ed8\u8ba4\u7aef\u53e3\uff09\u3002<\/p>\n<p><strong>4. \u63d0\u4f9b\u51ed\u636e<\/strong><\/p>\n<p>\u4f7f\u7528\u60a8\u5728\u542f\u52a8\u5bb9\u5668\u65f6\u6307\u5b9a\u7684 root \u5bc6\u7801\u8fde\u63a5\u3002<\/p>\n<p><strong>5. \u6307\u5b9a\u6570\u636e\u5e93<\/strong><\/p>\n<p>\u5982\u679c\u60a8\u5728\u542f\u52a8\u5bb9\u5668\u65f6\u6307\u5b9a\u4e86\u6570\u636e\u5e93\u540d\u79f0\uff0c\u8bf7\u5728\u8fde\u63a5\u65f6\u6307\u5b9a\u8be5\u540d\u79f0\u3002<\/p>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<p>\u4f7f\u7528 mysql \u547d\u4ee4\u884c\u5de5\u5177\u8fde\u63a5\uff1a<\/p>\n<pre>mysql -h &lt;mysql-container-ip&gt; -P 3306 -u root -p &lt;mysql-root-password&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4f7f\u7528 MySQL Workbench \u8fde\u63a5\uff1a<\/p>\n<ol>\n<li>\u6253\u5f00 MySQL Workbench\u3002<\/li>\n<li>\u5355\u51fb\u201c\u6570\u636e\u5e93\u201d&gt;\u201c\u8fde\u63a5\u201d\u3002<\/li>\n<li>\n<p>\u5728\u201c\u8fde\u63a5\u201d\u5bf9\u8bdd\u6846\u4e2d\uff0c\u8f93\u5165\u4ee5\u4e0b\u4fe1\u606f\uff1a<\/p>\n<ul>\n<li>\u4e3b\u673a\uff1a <\/li>\n<li>\u7aef\u53e3\uff1a3306<\/li>\n<li>\u7528\u6237\u540d\uff1aroot<\/li>\n<li>\u5bc6\u7801\uff1a <\/li>\n<li>\u6570\u636e\u5e93\uff1a \uff08\u53ef\u9009\uff09 <\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><strong>\u6ce8\u610f\uff1a<\/strong><\/p>\n<ul>\n<li>\u786e\u4fdd\u60a8\u7684\u4e3b\u673a\u548c\u5bb9\u5668\u4e4b\u95f4\u5141\u8bb8 TCP 3306 \u7aef\u53e3\u4e0a\u7684\u6d41\u91cf\u3002<\/li>\n<li>\u60a8\u53ef\u4ee5\u4f7f\u7528  logs my-mysql \u547d\u4ee4\u67e5\u770b MySQL \u5bb9\u5668\u7684\u65e5\u5fd7\u3002<\/li>\n<li>\u5bb9\u5668\u91cd\u65b0\u542f\u52a8\u540e\uff0cMySQL \u5bb9\u5668\u7684 IP \u5730\u5740\u53ef\u80fd\u6703\u66f4\u6539\uff0c\u56e0\u6b64\u60a8\u9700\u8981\u91cd\u65b0\u8fd0\u884c\u6b65\u9aa4 2 \u4ee5\u83b7\u53d6\u65b0\u5730\u5740\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u4e2d\u7684\u600e\u4e48\u8fde\u63a5\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8FDCServers\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8fde\u63a5 docker \u4e2d\u7684 mysql \u6570\u636e\u5e93\u53ea\u9700\u4e94\u4e2a\u6b65\u9aa4\uff1a\u542f\u52a8 mysql \u5bb9\u5668\u3002\u67e5\u627e\u5bb9\u5668\u7684 ip \u5730\u5740\u3002\u4f7f\u7528\u5916\u90e8\u5ba2\u6237\u7aef\u8fde\u63a5\u5230 ip \u5730\u5740\u548c 3306 \u7aef\u53e3\u3002\u8f93\u5165\u542f\u52a8\u65f6\u6307\u5b9a\u7684 root \u5bc6\u7801\u3002\u6307\u5b9a\u542f\u52a8\u65f6\u6307\u5b9a\u7684\u6570\u636e\u5e93\u540d\u79f0\uff08\u5982\u679c\u9002\u7528\uff09\u3002 \u5982\u4f55\u8fde\u63a5 Docker \u4e2d\u7684 MySQL \u6570\u636e\u5e93 \u8fde\u63a5 Docker \u4e2d\u7684 MySQL \u6570\u636e\u5e93\u7684\u8fc7\u7a0b\u5f88\u7b80\u5355\uff0c\u53ef\u4ee5\u5206\u4e3a\u4ee5\u4e0b\u6b65\u9aa4\uff1a 1. \u542f\u52a8 MySQL \u5bb9\u5668 docker run -d &#8211;name my-mysql -e MYSQL_ROOT_PASSWORD=my-secret-password -e MYSQL_DATABASE=my-database mysql:latest \u767b\u5f55\u540e\u590d\u5236 2. \u67e5\u627e MySQL \u5bb9\u5668\u7684 IP \u5730\u5740 docker inspect -f &#8216;{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}&#8217; my-mysql \u767b\u5f55\u540e\u590d\u5236 3. \u4f7f\u7528\u5916\u90e8 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-63805","post","type-post","status-publish","format-standard","hentry","category-os"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/63805","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=63805"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/63805\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=63805"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=63805"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=63805"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}