{"id":6207,"date":"2024-11-14T11:49:26","date_gmt":"2024-11-14T03:49:26","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6207\/"},"modified":"2024-11-14T11:49:26","modified_gmt":"2024-11-14T03:49:26","slug":"mysql%e5%a6%82%e4%bd%95%e6%b7%bb%e5%8a%a0%e7%94%a8%e6%88%b7%e6%9d%83%e9%99%90","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/6207\/","title":{"rendered":"mysql\u5982\u4f55\u6dfb\u52a0\u7528\u6237\u6743\u9650"},"content":{"rendered":"<blockquote><p>\n  \u6dfb\u52a0 mysql \u7528\u6237\u6743\u9650\u7684\u8fc7\u7a0b\u5305\u62ec\uff1a\u521b\u5efa\u7528\u6237\uff1acreate user &#8216;username&#8217;@&#8217;hostname&#8217; identified by &#8216;password&#8217;;\u6388\u4e88\u6743\u9650\uff1agrant on .* to &#8216;username&#8217;@&#8217;hostname&#8217;;\u6216grant all privileges on *.* to &#8216;username&#8217;@&#8217;hostname&#8217;;\u5237\u65b0\u6743\u9650\uff1aflush privileges;\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202406\/15\/2024061513242754680.jpg\" class=\"aligncenter\" title=\"mysql\u5982\u4f55\u6dfb\u52a0\u7528\u6237\u6743\u9650\u63d2\u56fe\" alt=\"mysql\u5982\u4f55\u6dfb\u52a0\u7528\u6237\u6743\u9650\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u6dfb\u52a0 MySQL \u7528\u6237\u6743\u9650<\/strong><\/p>\n<p>MySQL \u7528\u6237\u6743\u9650\u662f\u6388\u4e88\u7528\u6237\u8bbf\u95ee\u548c\u7ba1\u7406\u6570\u636e\u5e93\u7684\u80fd\u529b\u3002\u6dfb\u52a0\u7528\u6237\u6743\u9650\u662f\u4e00\u4e2a\u76f8\u5bf9\u7b80\u5355\u7684\u8fc7\u7a0b\uff0c\u53ef\u4ee5\u5206\u4ee5\u4e0b\u51e0\u4e2a\u6b65\u9aa4\u5b8c\u6210\uff1a<\/p>\n<p><strong>1. \u521b\u5efa\u7528\u6237<\/strong><\/p>\n<pre>CREATE USER 'username'@'hostname' IDENTIFIED BY 'password';<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ul>\n<li>\u66ff\u6362 username \u4e3a\u8981\u521b\u5efa\u7684\u7528\u6237\u540d\u3002<\/li>\n<li>\u66ff\u6362 hostname \u4e3a\u7528\u6237\u53ef\u4ee5\u4ece\u5176\u8fde\u63a5\u5230 MySQL \u670d\u52a1\u5668\u7684\u4e3b\u673a\u540d\uff0c\u6216\u8005\u4f7f\u7528\u901a\u914d\u7b26 % \u5141\u8bb8\u7528\u6237\u4ece\u4efb\u4f55\u4e3b\u673a\u8fde\u63a5\u3002<\/li>\n<li>\u66ff\u6362 password \u4e3a\u8981\u8bbe\u7f6e\u7684\u5bc6\u7801\u3002<\/li>\n<\/ul>\n<p><strong>2. \u6388\u4e88\u6743\u9650<\/strong><\/p>\n<p>\u4e00\u65e6\u7528\u6237\u88ab\u521b\u5efa\uff0c\u60a8\u5c31\u53ef\u4ee5\u6388\u4e88\u4ed6\u4eec\u6240\u9700\u8981\u7684\u6743\u9650\u3002\u6709\u8bb8\u591a\u4e0d\u540c\u7684\u6743\u9650\u53ef\u4f9b\u9009\u62e9\uff0c\u5177\u4f53\u53d6\u51b3\u4e8e\u60a8\u5e0c\u671b\u7528\u6237\u80fd\u591f\u6267\u884c\u7684\u64cd\u4f5c\u3002<\/p>\n<p>\u8981\u6388\u4e88\u7279\u5b9a\u6570\u636e\u5e93\u7684\u6743\u9650\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u8bed\u6cd5\uff1a<\/p>\n<pre>GRANT &lt;permissions&gt; ON &lt;database_name&gt;.* TO 'username'@'hostname';<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ul>\n<li>\u66ff\u6362 \u4e3a\u8981\u6388\u4e88\u7684\u6743\u9650\u3002\u53ef\u7528\u7684\u6743\u9650\u5305\u62ec SELECT\u3001INSERT\u3001UPDATE\u3001DELETE \u548c CREATE\u3002 <\/li>\n<li>\u66ff\u6362 \u4e3a\u8981\u6388\u4e88\u6743\u9650\u7684\u6570\u636e\u5e93\u7684\u540d\u79f0\u3002 <\/li>\n<\/ul>\n<p>\u8981\u6388\u4e88\u6240\u6709\u6570\u636e\u5e93\u7684\u6743\u9650\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u8bed\u6cd5\uff1a<\/p>\n<pre>GRANT ALL PRIVILEGES ON *.* TO 'username'@'hostname';<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>3. \u5237\u65b0\u6743\u9650<\/strong><\/p>\n<p>\u6700\u540e\uff0c\u4e3a\u4e86\u4f7f\u66f4\u6539\u751f\u6548\uff0c\u60a8\u9700\u8981\u5237\u65b0\u6743\u9650\uff1a<\/p>\n<pre>FLUSH PRIVILEGES;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u73b0\u5728\uff0c\u7528\u6237\u5c06\u62e5\u6709\u60a8\u6388\u4e88\u4ed6\u4eec\u7684\u6743\u9650\u3002\u8bf7\u6ce8\u610f\uff0c\u60a8\u53ea\u80fd\u6388\u4e88\u60a8\u81ea\u5df1\u62e5\u6709\u7684\u6743\u9650\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u6dfb\u52a0\u7528\u6237\u6743\u9650\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u7f51\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6dfb\u52a0 mysql \u7528\u6237\u6743\u9650\u7684\u8fc7\u7a0b\u5305\u62ec\uff1a\u521b\u5efa\u7528\u6237\uff1acreate user &#8216;username&#8217;@&#8217;hostname&#8217; identified by &#8216;password&#8217;;\u6388\u4e88\u6743\u9650\uff1agrant on .* to &#8216;username&#8217;@&#8217;hostname&#8217;;\u6216grant all privileges on *.* to &#8216;username&#8217;@&#8217;hostname&#8217;;\u5237\u65b0\u6743\u9650\uff1aflush privileges; \u5982\u4f55\u6dfb\u52a0 MySQL \u7528\u6237\u6743\u9650 MySQL \u7528\u6237\u6743\u9650\u662f\u6388\u4e88\u7528\u6237\u8bbf\u95ee\u548c\u7ba1\u7406\u6570\u636e\u5e93\u7684\u80fd\u529b\u3002\u6dfb\u52a0\u7528\u6237\u6743\u9650\u662f\u4e00\u4e2a\u76f8\u5bf9\u7b80\u5355\u7684\u8fc7\u7a0b\uff0c\u53ef\u4ee5\u5206\u4ee5\u4e0b\u51e0\u4e2a\u6b65\u9aa4\u5b8c\u6210\uff1a 1. \u521b\u5efa\u7528\u6237 CREATE USER &#8216;username&#8217;@&#8217;hostname&#8217; IDENTIFIED BY &#8216;password&#8217;; \u767b\u5f55\u540e\u590d\u5236 \u66ff\u6362 username \u4e3a\u8981\u521b\u5efa\u7684\u7528\u6237\u540d\u3002 \u66ff\u6362 hostname \u4e3a\u7528\u6237\u53ef\u4ee5\u4ece\u5176\u8fde\u63a5\u5230 MySQL \u670d\u52a1\u5668\u7684\u4e3b\u673a\u540d\uff0c\u6216\u8005\u4f7f\u7528\u901a\u914d\u7b26 % \u5141\u8bb8\u7528\u6237\u4ece\u4efb\u4f55\u4e3b\u673a\u8fde\u63a5\u3002 \u66ff\u6362 password \u4e3a\u8981\u8bbe\u7f6e\u7684\u5bc6\u7801\u3002 2. \u6388\u4e88\u6743\u9650 \u4e00\u65e6\u7528\u6237\u88ab\u521b\u5efa\uff0c\u60a8\u5c31\u53ef\u4ee5\u6388\u4e88\u4ed6\u4eec\u6240\u9700\u8981\u7684\u6743\u9650\u3002\u6709\u8bb8\u591a\u4e0d\u540c\u7684\u6743\u9650\u53ef\u4f9b\u9009\u62e9\uff0c\u5177\u4f53\u53d6\u51b3\u4e8e\u60a8\u5e0c\u671b\u7528\u6237\u80fd\u591f\u6267\u884c\u7684\u64cd\u4f5c\u3002 \u8981\u6388\u4e88\u7279\u5b9a\u6570\u636e\u5e93\u7684\u6743\u9650\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u8bed\u6cd5\uff1a GRANT &lt;permissions&gt; ON &lt;database_name&gt;.* TO [&hellip;]<\/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-6207","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6207","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=6207"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6207\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6207"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6207"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6207"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}