{"id":200773,"date":"2025-05-06T10:41:57","date_gmt":"2025-05-06T02:41:57","guid":{"rendered":"https:\/\/server.hk\/cnblog\/200773\/"},"modified":"2025-05-06T10:41:57","modified_gmt":"2025-05-06T02:41:57","slug":"docker-mysql-%e5%a6%82%e4%bd%95%e8%87%aa%e5%ae%9a%e4%b9%89%e5%ad%97%e7%ac%a6%e9%9b%86%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/200773\/","title":{"rendered":"Docker MySQL \u5982\u4f55\u81ea\u5b9a\u4e49\u5b57\u7b26\u96c6\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>Docker MySQL \u5982\u4f55\u81ea\u5b9a\u4e49\u5b57\u7b26\u96c6\uff1f<\/h1>\n<p>\u4ece\u73b0\u5728\u5f00\u59cb\uff0c\u52aa\u529b\u5b66\u4e60\u5427\uff01\u672c\u6587\u4e3b\u8981\u8bb2\u89e3\u4e86\u7b49\u7b49\u76f8\u5173\u77e5\u8bc6\u70b9\uff0c\u6211\u4f1a\u5728\u4e3b\u673a\u5b9d\u8d1d\u4e2d\u6301\u7eed\u66f4\u65b0\u76f8\u5173\u7684\u7cfb\u5217\u6587\u7ae0\uff0c\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8\u5e76\u79ef\u6781\u7559\u8a00\u5efa\u8bae\u3002\u4e0b\u9762\u5c31\u5148\u4e00\u8d77\u6765\u770b\u4e00\u4e0b\u672c\u7bc7\u6b63\u6587\u5185\u5bb9\u5427\uff0c\u5e0c\u671b\u80fd\u5e2e\u5230\u4f60\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241114\/17315600786735828e9762f.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>\u901a\u8fc7\u81ea\u5b9a\u4e49\u914d\u7f6e\u6587\u4ef6\u4e3a docker mysql \u6307\u5b9a\u5b57\u7b26\u96c6<\/strong><\/p>\n<p>\u4f7f\u7528 &#8211;character-set-server \u9009\u9879\u542f\u52a8 docker mysql \u5bb9\u5668\u65f6\u65e0\u6cd5\u6b63\u786e\u6307\u5b9a\u5b57\u7b26\u96c6\u3002\u53ef\u4ee5\u901a\u8fc7\u521b\u5efa\u5e76\u6302\u8f7d\u81ea\u5b9a\u4e49\u914d\u7f6e\u6587\u4ef6\u6765\u89e3\u51b3\u6b64\u95ee\u9898\u3002<\/p>\n<p><strong>\u6b65\u9aa4\uff1a<\/strong><\/p>\n<ol>\n<li><strong>\u521b\u5efa\u81ea\u5b9a\u4e49\u914d\u7f6e\u6587\u4ef6\uff1a<\/strong><br \/>\u5728\u5bbf\u4e3b\u673a\u521b\u5efa\u4e00\u4e2a .cnf \u6269\u5c55\u540d\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u4f8b\u5982 character_set.cnf\u3002<\/li>\n<li>\n<p><strong>\u6dfb\u52a0\u914d\u7f6e\u6587\u4ef6\u5185\u5bb9\uff1a<\/strong><br \/>\u5c06\u4ee5\u4e0b\u5185\u5bb9\u7c98\u8d34\u5230\u914d\u7f6e\u6587\u4ef6\u4e2d\uff1a<\/p>\n<pre>[mysqld]\ncharacter-set-server = utf8mb4\n[client]\ndefault-character-set = utf8mb4\n[mysql]\ndefault-character-set = utf8mb4<\/pre>\n<\/li>\n<li>\n<p><strong>\u542f\u52a8\u5bb9\u5668\u5e76\u6302\u8f7d\u914d\u7f6e\u6587\u4ef6\uff1a<\/strong><br \/>\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u542f\u52a8\u5bb9\u5668\uff0c\u5c06 \u6302\u8f7d\u81ea\u5b9a\u4e49\u914d\u7f6e\u6587\u4ef6\u7684\u76ee\u5f55\/path\/to\/custom \u5230\u5bb9\u5668\u7684 \/etc\/mysql\/conf.d \u76ee\u5f55\uff1a<\/p>\n<pre>docker run \\\n    --name mysql \\\n    -v \/path\/to\/custom:\/etc\/mysql\/conf.d \\\n    -e mysql_root_password=my-secret-pw \\\n    -d mysql:tag<\/pre>\n<\/li>\n<li>\n<p><strong>\u9a8c\u8bc1\u5b57\u7b26\u96c6\uff1a<\/strong><br \/>\u8fdb\u5165\u5bb9\u5668\u5e76\u767b\u5f55 mysql\uff0c\u8fd0\u884c\u4ee5\u4e0b\u67e5\u8be2\u68c0\u67e5\u5b57\u7b26\u96c6\uff1a<\/p>\n<pre>show variables like '%char%';<\/pre>\n<p>\u8f93\u51fa\u5e94\u663e\u793a\u5b57\u7b26\u96c6\u5df2\u6b63\u786e\u8bbe\u7f6e\u4e3a utf8mb4\u3002<\/p>\n<\/li>\n<\/ol>\n<p>\u4ee5\u4e0a\u5c31\u662f\u672c\u6587\u7684\u5168\u90e8\u5185\u5bb9\u4e86\uff0c\u662f\u5426\u6709\u987a\u5229\u5e2e\u52a9\u4f60\u89e3\u51b3\u95ee\u9898\uff1f\u82e5\u662f\u80fd\u7ed9\u4f60\u5e26\u6765\u5b66\u4e60\u4e0a\u7684\u5e2e\u52a9\uff0c\u8bf7\u5927\u5bb6\u591a\u591a\u652f\u6301\u4e3b\u673a\u5b9d\u8d1d\uff01\u66f4\u591a\u5173\u4e8e\u6570\u636e\u5e93\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u4e5f\u53ef\u5173\u6ce8\u4e3b\u673a\u5b9d\u8d1d\u516c\u4f17\u53f7\u3002<\/p>\n<dl>\n<dt>\n <\/dt>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>Docker MySQL \u5982\u4f55\u81ea&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-200773","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/200773","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"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=200773"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/200773\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=200773"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=200773"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=200773"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}