{"id":18254,"date":"2024-11-18T10:21:36","date_gmt":"2024-11-18T02:21:36","guid":{"rendered":"https:\/\/fwq.ai\/blog\/18254\/"},"modified":"2024-11-18T10:21:36","modified_gmt":"2024-11-18T02:21:36","slug":"docker%e8%bf%90%e8%a1%8cmysql%e6%80%8e%e4%b9%88%e9%85%8d%e7%bd%ae","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/18254\/","title":{"rendered":"docker\u8fd0\u884cmysql\u600e\u4e48\u914d\u7f6e"},"content":{"rendered":"<blockquote><p>\n  \u5728 docker \u4e2d\u914d\u7f6e mysql \u6d89\u53ca\u4ee5\u4e0b\u6b65\u9aa4\uff1a\u521b\u5efa\u57fa\u4e8e mysql \u5b98\u65b9\u955c\u50cf\u7684 docker \u955c\u50cf\u3002\u542f\u52a8\u5bb9\u5668\uff0c\u5e76\u6307\u5b9a mysql \u6839\u5bc6\u7801\u3001\u6570\u636e\u5e93\u540d\u79f0\u548c\u7aef\u53e3\u6620\u5c04\u3002\u4f7f\u7528 docker exec \u547d\u4ee4\u8fde\u63a5\u5230\u5bb9\u5668\uff0c\u5e76\u4f7f\u7528 mysql \u547d\u4ee4\u884c\u754c\u9762\u8fdb\u884c\u914d\u7f6e\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202406\/05\/2024060506391961090.jpg\" class=\"aligncenter\" title=\"docker\u8fd0\u884cmysql\u600e\u4e48\u914d\u7f6e\u63d2\u56fe\" alt=\"docker\u8fd0\u884cmysql\u600e\u4e48\u914d\u7f6e\u63d2\u56fe\" \/><\/p>\n<p><strong>Docker \u4e2d\u8fd0\u884c MySQL \u7684\u914d\u7f6e<\/strong><\/p>\n<p><strong>\u5982\u4f55\u914d\u7f6e Docker \u4e2d\u7684 MySQL\uff1f<\/strong><\/p>\n<p>\u5728 Docker \u4e2d\u914d\u7f6e MySQL \u4e3b\u8981\u6d89\u53ca\u4e09\u4e2a\u5173\u952e\u6b65\u9aa4\uff1a<\/p>\n<p><strong>1. \u521b\u5efa Docker \u955c\u50cf<\/strong><\/p>\n<p>\u521b\u5efa\u4e00\u4e2a\u57fa\u4e8e MySQL \u5b98\u65b9\u955c\u50cf\u7684 Docker \u955c\u50cf\u3002\u60a8\u9700\u8981\u6307\u5b9a\u6240\u9700\u7684 MySQL \u7248\u672c\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre>docker build -t my-mysql-image .<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>2. \u542f\u52a8\u5e76\u914d\u7f6e\u5bb9\u5668<\/strong><\/p>\n<p>\u4f7f\u7528\u521b\u5efa\u7684\u955c\u50cf\u542f\u52a8\u4e00\u4e2a Docker \u5bb9\u5668\uff0c\u5e76\u6307\u5b9a\u5fc5\u8981\u914d\u7f6e\uff1a<\/p>\n<pre>docker run -d --name my-mysql-container \n-e MYSQL_ROOT_PASSWORD=your_password \n-e MYSQL_DATABASE=your_database \n-p 3306:3306 \nmy-mysql-image<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5176\u4e2d\uff1a<\/p>\n<ul>\n<li>-e MYSQL_ROOT_PASSWORD \u8bbe\u7f6e MySQL root \u7528\u6237\u7684\u5bc6\u7801\u3002<\/li>\n<li>-e MYSQL_DATABASE \u521b\u5efa\u4e00\u4e2a\u540d\u4e3a your_database \u7684\u6570\u636e\u5e93\u3002<\/li>\n<li>-p 3306:3306 \u5c06\u5bb9\u5668\u5185\u7684 MySQL \u7aef\u53e3\u6620\u5c04\u5230\u4e3b\u673a\u4e0a\u7684 3306 \u7aef\u53e3\u3002<\/li>\n<\/ul>\n<p><strong>3. \u8fde\u63a5\u5230\u5bb9\u5668<\/strong><\/p>\n<p>\u4f7f\u7528  exec \u547d\u4ee4\u8fde\u63a5\u5230\u5bb9\u5668\uff0c\u5e76\u4f7f\u7528 MySQL \u547d\u4ee4\u884c\u754c\u9762\u8fdb\u884c\u914d\u7f6e\uff1a<\/p>\n<pre>docker exec -it my-mysql-container bash\nmysql -u root -p<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u8be6\u7ec6\u8bf4\u660e\uff1a<\/strong><\/p>\n<ul>\n<li> <strong>\u73af\u5883\u53d8\u91cf\uff1a<\/strong>\u60a8\u53ef\u4ee5\u5728\u542f\u52a8 Docker \u5bb9\u5668\u65f6\u6307\u5b9a\u73af\u5883\u53d8\u91cf\uff0c\u4ee5\u914d\u7f6e MySQL \u670d\u52a1\u5668\uff0c\u4f8b\u5982\u6839\u5bc6\u7801\u548c\u6240\u9700\u6570\u636e\u5e93\u7684\u540d\u79f0\u3002<\/li>\n<li> <strong>\u7aef\u53e3\u6620\u5c04\uff1a<\/strong>\u60a8\u53ef\u4ee5\u4f7f\u7528 -p \u6807\u5fd7\u5c06\u5bb9\u5668\u5185\u7684\u7aef\u53e3\u6620\u5c04\u5230\u4e3b\u673a\u4e0a\u7684\u7aef\u53e3\uff0c\u8fd9\u5c06\u5141\u8bb8\u60a8\u4ece\u4e3b\u673a\u8bbf\u95ee MySQL\u3002<\/li>\n<li> <strong>MySQL \u547d\u4ee4\u884c\u754c\u9762\uff1a<\/strong>\u8fde\u63a5\u5230\u5bb9\u5668\u540e\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528 MySQL \u547d\u4ee4\u884c\u754c\u9762\u8fdb\u884c\u8fdb\u4e00\u6b65\u914d\u7f6e\uff0c\u4f8b\u5982\u521b\u5efa\u7528\u6237\u3001\u6388\u4e88\u6743\u9650\u548c\u67e5\u8be2\u6570\u636e\u3002<\/li>\n<\/ul>\n<p>\u901a\u8fc7\u9075\u5faa\u8fd9\u4e9b\u6b65\u9aa4\uff0c\u60a8\u53ef\u4ee5\u5728 Docker \u4e2d\u6210\u529f\u914d\u7f6e\u548c\u8fd0\u884c MySQL\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u8fd0\u884c\u600e\u4e48\u914d\u7f6e\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728 docker \u4e2d\u914d\u7f6e mysql \u6d89\u53ca\u4ee5\u4e0b\u6b65\u9aa4\uff1a\u521b\u5efa\u57fa\u4e8e mysql \u5b98\u65b9\u955c\u50cf\u7684 docker \u955c\u50cf\u3002\u542f\u52a8\u5bb9\u5668\uff0c\u5e76\u6307\u5b9a mysql \u6839\u5bc6\u7801\u3001\u6570\u636e\u5e93\u540d\u79f0\u548c\u7aef\u53e3\u6620\u5c04\u3002\u4f7f\u7528 docker exec \u547d\u4ee4\u8fde\u63a5\u5230\u5bb9\u5668\uff0c\u5e76\u4f7f\u7528 mysql \u547d\u4ee4\u884c\u754c\u9762\u8fdb\u884c\u914d\u7f6e\u3002 Docker \u4e2d\u8fd0\u884c MySQL \u7684\u914d\u7f6e \u5982\u4f55\u914d\u7f6e Docker \u4e2d\u7684 MySQL\uff1f \u5728 Docker \u4e2d\u914d\u7f6e MySQL \u4e3b\u8981\u6d89\u53ca\u4e09\u4e2a\u5173\u952e\u6b65\u9aa4\uff1a 1. \u521b\u5efa Docker \u955c\u50cf \u521b\u5efa\u4e00\u4e2a\u57fa\u4e8e MySQL \u5b98\u65b9\u955c\u50cf\u7684 Docker \u955c\u50cf\u3002\u60a8\u9700\u8981\u6307\u5b9a\u6240\u9700\u7684 MySQL \u7248\u672c\uff0c\u4f8b\u5982\uff1a docker build -t my-mysql-image . \u767b\u5f55\u540e\u590d\u5236 2. \u542f\u52a8\u5e76\u914d\u7f6e\u5bb9\u5668 \u4f7f\u7528\u521b\u5efa\u7684\u955c\u50cf\u542f\u52a8\u4e00\u4e2a Docker \u5bb9\u5668\uff0c\u5e76\u6307\u5b9a\u5fc5\u8981\u914d\u7f6e\uff1a docker run -d &#8211;name [&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-18254","post","type-post","status-publish","format-standard","hentry","category-os"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/18254","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=18254"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/18254\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=18254"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=18254"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=18254"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}