{"id":200603,"date":"2025-05-06T13:55:48","date_gmt":"2025-05-06T05:55:48","guid":{"rendered":"https:\/\/server.hk\/cnblog\/200603\/"},"modified":"2025-05-06T13:55:48","modified_gmt":"2025-05-06T05:55:48","slug":"%e8%bf%9c%e7%a8%8b%e6%95%b0%e6%8d%ae%e5%ba%93%e8%b4%a6%e6%88%b7%e5%88%9b%e5%bb%ba%e6%88%90%e5%8a%9f%e5%8d%b4%e6%97%a0%e6%b3%95%e8%bf%9e%e6%8e%a5%ef%bc%9ainit_connect-%e5%91%bd%e4%bb%a4%e5%bc%95","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/200603\/","title":{"rendered":"\u8fdc\u7a0b\u6570\u636e\u5e93\u8d26\u6237\u521b\u5efa\u6210\u529f\u5374\u65e0\u6cd5\u8fde\u63a5\uff1ainit_connect \u547d\u4ee4\u5f15\u53f7\u5bfc\u81f4\u7684\u95ee\u9898"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>\u8fdc\u7a0b\u6570\u636e\u5e93\u8d26\u6237\u521b\u5efa\u6210\u529f\u5374\u65e0\u6cd5\u8fde\u63a5\uff1ainit_connect \u547d\u4ee4\u5f15\u53f7\u5bfc\u81f4\u7684\u95ee\u9898<\/h1>\n<p>\u5bf9\u4e8e\u4e00\u4e2a\u6570\u636e\u5e93\u5f00\u53d1\u8005\u6765\u8bf4\uff0c\u7262\u56fa\u624e\u5b9e\u7684\u57fa\u7840\u662f\u5341\u5206\u91cd\u8981\u7684\uff0c\u4e3b\u673a\u5b9d\u8d1d\u5c31\u6765\u5e26\u5927\u5bb6\u4e00\u70b9\u70b9\u7684\u638c\u63e1\u57fa\u7840\u77e5\u8bc6\u70b9\u3002\u4eca\u5929\u672c\u7bc7\u6587\u7ae0\u5e26\u5927\u5bb6\u4e86\u89e3\u300a\u8fdc\u7a0b\u6570\u636e\u5e93\u8d26\u6237\u521b\u5efa\u6210\u529f\u5374\u65e0\u6cd5\u8fde\u63a5\uff1ainit_connect \u547d\u4ee4\u5f15\u53f7\u5bfc\u81f4\u7684\u95ee\u9898\u300b\uff0c\u4e3b\u8981\u4ecb\u7ecd\u4e86\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u5feb\u70b9\u6536\u85cf\u8d77\u6765\u5427\uff0c\u5426\u5219\u9700\u8981\u65f6\u5c31\u627e\u4e0d\u5230\u4e86\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241109\/1731145152672f2dc084628.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>\u521b\u5efa\u8fdc\u7a0b\u8bbf\u95ee\u6570\u636e\u5e93\u8d26\u6237\u5374\u65e0\u6cd5\u8fde\u63a5\uff0c\u539f\u56e0\u4f55\u5728\uff1f<\/strong><\/p>\n<p>\u95ee\u9898\u63cf\u8ff0\uff1a<\/p>\n<p>\u8fdc\u7a0b\u4e3b\u673a\u4e0a\u7684 root \u7528\u6237\u53ef\u4ee5\u8bbf\u95ee\u6570\u636e\u5e93\uff0c\u4f46\u4f7f\u7528\u4ee5\u4e0b\u8bed\u53e5\u521b\u5efa\u7684 auser \u7528\u6237\uff0c\u5374\u65e0\u6cd5\u8fdc\u7a0b\u767b\u5f55\u3002<\/p>\n<pre>create user 'auser'@'%' identified by 'auser';\ngrant all on `mydb`.* to 'auser'@'%';\nflush privileges;<\/pre>\n<p>\u5728 navicat \u4e2d\u767b\u5f55 auser \u8d26\u6237\u65f6\uff0c\u4f1a\u51fa\u73b0 2013 &#8211; lost connection to mysql server during query \u7684\u63d0\u793a\u3002<\/p>\n<p>\u95ee\u9898\u5206\u6790\uff1a<\/p>\n<p>\u4ee5 mysql \u547d\u4ee4\u767b\u5f55 auser \u8d26\u6237\u540e\u53d1\u73b0\uff0c\u63d0\u793a init_connect command failed\u3002\u5728\u7f51\u4e0a\u67e5\u9605\u540e\u53d1\u73b0\uff0c\u9700\u8981\u4fee\u6539 \/etc\/my.cnf \u6587\u4ef6\uff0c\u5c06\u4ee5\u4e0b\u4e24\u884c\u7684 \u201c (\u53cc\u5f15\u53f7) \u6539\u4e3a &#8216; (\u5355\u5f15\u53f7)\u3002<\/p>\n<pre>init_connect=\u2018set collation_connection = utf8_unicode_ci\u2019\ninit_connect=\u2018set names utf8\u2019<\/pre>\n<p>\u6539\u4e3a\uff1a<\/p>\n<pre>init_connect='SET collation_connection = utf8_unicode_ci'\ninit_connect='SET NAMES utf8'<\/pre>\n<p>\u540e\u7eed\u64cd\u4f5c\uff1a<\/p>\n<p>\u5b8c\u6210\u540e\u91cd\u542f mysqld \u670d\u52a1\uff0c\u95ee\u9898\u89e3\u51b3\u3002<\/p>\n<p>\u597d\u4e86\uff0c\u672c\u6587\u5230\u6b64\u7ed3\u675f\uff0c\u5e26\u5927\u5bb6\u4e86\u89e3\u4e86\u300a\u8fdc\u7a0b\u6570\u636e\u5e93\u8d26\u6237\u521b\u5efa\u6210\u529f\u5374\u65e0\u6cd5\u8fde\u63a5\uff1ainit_connect \u547d\u4ee4\u5f15\u53f7\u5bfc\u81f4\u7684\u95ee\u9898\u300b\uff0c\u5e0c\u671b\u672c\u6587\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff01\u5173\u6ce8\u4e3b\u673a\u5b9d\u8d1d\u516c\u4f17\u53f7\uff0c\u7ed9\u5927\u5bb6\u5206\u4eab\u66f4\u591a\u6570\u636e\u5e93\u77e5\u8bc6\uff01<\/p>\n<dl>\n<dt>\n <\/dt>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>\u8fdc\u7a0b\u6570\u636e\u5e93\u8d26\u6237\u521b\u5efa\u6210\u529f\u5374\u65e0\u6cd5\u8fde\u63a5&#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-200603","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/200603","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=200603"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/200603\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=200603"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=200603"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=200603"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}