{"id":232,"date":"2021-09-27T21:21:20","date_gmt":"2021-09-27T13:21:20","guid":{"rendered":"https:\/\/fugary.com\/?p=232"},"modified":"2021-09-27T21:21:20","modified_gmt":"2021-09-27T13:21:20","slug":"%e6%9c%ac%e5%9c%b0docker%e7%8e%af%e5%a2%83%e5%ae%89%e8%a3%85mysql","status":"publish","type":"post","link":"https:\/\/fugary.com\/?p=232","title":{"rendered":"\u672c\u5730Docker\u73af\u5883\u5b89\u88c5MySQL"},"content":{"rendered":"<p>\u9996\u5148\u672c\u5730\u5df2\u7ecf\u6709docker\u73af\u5883\u5b58\u5728\uff0c\u7136\u540e\u53ef\u4ee5\u62c9\u53d6MySQL\u955c\u50cf\u3002<\/p>\n<h3>\u5730\u5740<\/h3>\n<p>\u76f8\u5173mysql\u4ed3\u5e93\u5730\u5740\uff1a<\/p>\n<p><a href=\"https:\/\/hub.docker.com\/_\/mysql\/\">https:\/\/hub.docker.com\/_\/mysql\/<\/a><\/p>\n<h3>\u62c9\u53d6MySQL\u955c\u50cf<\/h3>\n<pre><code class=\"language-sh\"># \u955c\u50cf\u62c9\u53d6 docker pull mysql:8.0.26\ndocker pull mysql:latest\n# \u67e5\u770b\u955c\u50cf\u5217\u8868\ndocker image ls<\/code><\/pre>\n<p>\u7b49\u5f85\u955c\u50cf\u5b8c\u6210\u4e4b\u540e\u5c31\u53ef\u4ee5\u542f\u52a8mysql\u4e86\uff0c\u6ce8\u610f\u9700\u8981\u914d\u7f6e\u4e00\u4e9b\u542f\u52a8\u53c2\u6570<\/p>\n<h3>\u542f\u52a8MySQL\u955c\u50cf<\/h3>\n<pre><code class=\"language-sh\"># \u542f\u52a8\u547d\u4ee4\ndocker run -it --name mysql-name -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql:latest\n# \u5982\u679c\u8981\u540e\u53f0\u542f\u52a8\u52a0-d\u53c2\u6570\ndocker run -itd --name mysql-name -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql:latest\n# \u67e5\u770b\u5bb9\u5668\ndocker ps\n# \u67e5\u770b\u5bb9\u5668\uff0c\u5305\u62ec\u5df2\u7ecf\u505c\u6b62\u7684\ndocker ps -a\n# \u505c\u6b62\u955c\u50cf\ndocker kill \u5bb9\u5668id\n# \u518d\u6b21\u542f\u52a8\u5df2\u7ecf\u505c\u6b62\u7684\u5bb9\u5668\ndocker start \u5bb9\u5668id<\/code><\/pre>\n<h3>\u53ef\u914d\u7f6e\u53c2\u6570<\/h3>\n<p>MySQL\u63d0\u4f9b\u4e86\u5f88\u591a\u73af\u5883\u53d8\u91cf\u53c2\u6570\uff0c\u53ef\u4ee5\u81ea\u5b9a\u4e49MySQL\u73af\u5883\uff0c\u5e38\u7528\u7684\u5982\u4e0b\uff1a<\/p>\n<p>\u53c2\u8003\u5730\u5740\uff1a<a href=\"https:\/\/dev.mysql.com\/doc\/refman\/5.7\/en\/environment-variables.html\">https:\/\/dev.mysql.com\/doc\/refman\/5.7\/en\/environment-variables.html<\/a><\/p>\n<table>\n<thead>\n<tr>\n<th>\u53c2\u6570\u540d<\/th>\n<th>\u8bf4\u660e<\/th>\n<th>\u9ed8\u8ba4\u503c<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><code>MYSQL_ROOT_PASSWORD<\/code><\/td>\n<td>root\u7528\u6237\u7684\u5bc6\u7801<\/td>\n<td>my-secret-pw<\/td>\n<\/tr>\n<tr>\n<td><code>MYSQL_DATABASE<\/code><\/td>\n<td>\u81ea\u5b9a\u4e49\u65b0\u6570\u636e\u5e93\u540d\u79f0<\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td><code>MYSQL_USER<\/code><\/td>\n<td>\u81ea\u5b9a\u4e49\u7528\u6237\u540d<\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td><code>MYSQL_PASSWORD<\/code><\/td>\n<td>\u81ea\u5b9a\u4e49\u7528\u6237\u5bc6\u7801<\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td><code>MYSQL_ALLOW_EMPTY_PASSWORD<\/code><\/td>\n<td>\u662f\u5426\u5141\u8bb8\u542f\u52a8root\u5bc6\u7801\u662f\u7a7a\u5bc6\u7801\uff1a\u975e\u7a7a\u8868\u793ayes<\/td>\n<td>\u7a7a\u8868\u793ano<\/td>\n<\/tr>\n<tr>\n<td><code>MYSQL_RANDOM_ROOT_PASSWORD<\/code><\/td>\n<td>\u4f7f\u7528\u968f\u673aroot\u5bc6\u7801\uff0c\u4e00\u822c\u4ece\u65e5\u5fd7\u4e2d\u67e5\u627e\u5bc6\u7801\uff1a\u975e\u7a7a\u8868\u793ayes<\/td>\n<td>\u7a7a\u8868\u793ano<\/td>\n<\/tr>\n<tr>\n<td><code>MYSQL_ONETIME_PASSWORD<\/code><\/td>\n<td>root\u4f7f\u7528\u4e00\u6b21\u6027\u5bc6\u7801\uff1a\u975e\u7a7a\u8868\u793ayes\uff0c\u767b\u5f55\u540e\u5f3a\u5236\u8981\u6c42\u4fee\u6539<\/td>\n<td>\u7a7a\u8868\u793ano<\/td>\n<\/tr>\n<tr>\n<td><code>MYSQL_INITDB_SKIP_TZINFO<\/code><\/td>\n<td>CONVERT_TZ()\u83b7\u53d6\u65f6\u533a\uff0c\u975e\u7a7a\u8868\u793adisable<\/td>\n<td><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u4e00\u822c\u4f7f\u7528<code>MYSQL_ROOT_PASSWORD<\/code>\u5c31\u53ef\u4ee5\u4e86<\/p>\n<h3>\u914d\u7f6e\u672c\u5730\u5377<\/h3>\n<p>\u4e0a\u9762\u7684\u60c5\u51b5\u4e0b\u542f\u52a8\u7684MySQL\u80fd\u591f\u6ee1\u8db3\u57fa\u672c\u9700\u6c42\uff0c\u4e0d\u8fc7\u6bcf\u6b21\u91cd\u542f\u4e4b\u540e\u6570\u636e\u5c31\u4e22\u5931\u4e86\uff0c\u5c31\u7b97\u662f\u5f00\u53d1\u73af\u5883\u8fd9\u6837\u4e5f\u4e0d\u80fd\u63a5\u53d7\u7684\uff0c\u9700\u8981\u6302\u63a5\u672c\u5730\u78c1\u76d8\uff0c\u65b9\u4fbf\u4e0b\u6b21\u53ef\u4ee5\u8bbf\u95ee\u3002<\/p>\n<p>\u9996\u5148\u53ef\u4ee5\u9009\u62e9\u4e00\u4e2a\u672c\u5730\u6587\u4ef6\u8def\u5f84\uff0c\u5982\uff1a<code>C:\/MySQL\/data<\/code>\uff0c\u7136\u540e\u6620\u5c04\u5230<code>\/var\/lib\/mysql<\/code>\uff0c\u589e\u52a0\u547d\u4ee4\u53c2\u6570\uff1a<code> -v C:\/MySQL\/data:\/var\/lib\/mysql<\/code>\uff0c\u5b8c\u6574\u547d\u4ee4\uff1a<\/p>\n<pre><code class=\"language-sh\">docker run -itd --name mysql-name -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 -v C:\/MySQL\/data:\/var\/lib\/mysql mysql:latest<\/code><\/pre>\n<p>\u5982\u679c\u8fd8\u8981\u81ea\u5b9a\u4e49\u914d\u7f6e\u6587\u4ef6\u53ef\u4ee5\u518d\u589e\u52a0\uff1a<code>-v C:\/MySQL\/config:\/etc\/mysql\/conf.d<\/code><\/p>\n<p>\u7136\u540e\u53ef\u4ee5\u7528\u5ba2\u6237\u7aef\u767b\u5f55\u4e86\uff0c\u800c\u4e14\u4e0b\u6b21\u542f\u52a8\u4e0d\u4f1a\u4e22\u5931\u6570\u636e\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u9996\u5148\u672c\u5730\u5df2\u7ecf\u6709docker\u73af\u5883\u5b58\u5728\uff0c\u7136\u540e\u53ef\u4ee5\u62c9\u53d6MySQL\u955c\u50cf\u3002 \u5730\u5740 \u76f8\u5173mysql\u4ed3\u5e93\u5730\u5740\uff1a https: [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[14,2],"tags":[44,12],"_links":{"self":[{"href":"https:\/\/fugary.com\/index.php?rest_route=\/wp\/v2\/posts\/232"}],"collection":[{"href":"https:\/\/fugary.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fugary.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fugary.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fugary.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=232"}],"version-history":[{"count":1,"href":"https:\/\/fugary.com\/index.php?rest_route=\/wp\/v2\/posts\/232\/revisions"}],"predecessor-version":[{"id":233,"href":"https:\/\/fugary.com\/index.php?rest_route=\/wp\/v2\/posts\/232\/revisions\/233"}],"wp:attachment":[{"href":"https:\/\/fugary.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=232"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fugary.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=232"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fugary.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=232"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}