{"id":26568,"date":"2024-11-24T16:10:43","date_gmt":"2024-11-24T08:10:43","guid":{"rendered":"https:\/\/fwq.ai\/blog\/26568\/"},"modified":"2024-11-24T16:10:43","modified_gmt":"2024-11-24T08:10:43","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-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/26568\/","title":{"rendered":"Docker MySQL \u5982\u4f55\u81ea\u5b9a\u4e49\u5b57\u7b26\u96c6\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173098801371098.jpg\" class=\"aligncenter\" title=\"Docker MySQL \u5982\u4f55\u81ea\u5b9a\u4e49\u5b57\u7b26\u96c6\uff1f\u63d2\u56fe\" alt=\"Docker MySQL \u5982\u4f55\u81ea\u5b9a\u4e49\u5b57\u7b26\u96c6\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u901a\u8fc7\u81ea\u5b9a\u4e49\u914d\u7f6e\u6587\u4ef6\u4e3a   \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<p> \u767b\u5f55\u540e\u590d\u5236 <\/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<p> \u767b\u5f55\u540e\u590d\u5236 <\/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> \u767b\u5f55\u540e\u590d\u5236 <\/p>\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\u662fDocker MySQL \u5982\u4f55\u81ea\u5b9a\u4e49\u5b57\u7b26\u96c6\uff1f\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>\u901a\u8fc7\u81ea\u5b9a\u4e49\u914d\u7f6e\u6587\u4ef6\u4e3a \u6307\u5b9a\u5b57\u7b26\u96c6 \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 \u6b65\u9aa4\uff1a \u521b\u5efa\u81ea\u5b9a\u4e49\u914d\u7f6e\u6587\u4ef6\uff1a\u5728\u5bbf\u4e3b\u673a\u521b\u5efa\u4e00\u4e2a .cnf \u6269\u5c55\u540d\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u4f8b\u5982 character_set.cnf\u3002 \u6dfb\u52a0\u914d\u7f6e\u6587\u4ef6\u5185\u5bb9\uff1a\u5c06\u4ee5\u4e0b\u5185\u5bb9\u7c98\u8d34\u5230\u914d\u7f6e\u6587\u4ef6\u4e2d\uff1a [mysqld] character-set-server = utf8mb4 [client] default-character-set = utf8mb4 [mysql] default-character-set = utf8mb4 \u767b\u5f55\u540e\u590d\u5236 \u542f\u52a8\u5bb9\u5668\u5e76\u6302\u8f7d\u914d\u7f6e\u6587\u4ef6\uff1a\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 docker run &#8211;name mysql -v \/path\/to\/custom:\/etc\/mysql\/conf.d -e mysql_root_password=my-secret-pw -d mysql:tag \u767b\u5f55\u540e\u590d\u5236 \u9a8c\u8bc1\u5b57\u7b26\u96c6\uff1a\u8fdb\u5165\u5bb9\u5668\u5e76\u767b\u5f55 mysql\uff0c\u8fd0\u884c\u4ee5\u4e0b\u67e5\u8be2\u68c0\u67e5\u5b57\u7b26\u96c6\uff1a show variables like &#8216;%char%&#8217;; \u767b\u5f55\u540e\u590d\u5236 \u8f93\u51fa\u5e94\u663e\u793a\u5b57\u7b26\u96c6\u5df2\u6b63\u786e\u8bbe\u7f6e\u4e3a utf8mb4\u3002 \u4ee5\u4e0a\u5c31\u662fDocker MySQL \u5982\u4f55\u81ea\u5b9a\u4e49\u5b57\u7b26\u96c6\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/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-26568","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/26568","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=26568"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/26568\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=26568"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=26568"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=26568"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}