{"id":5448,"date":"2024-11-14T11:54:56","date_gmt":"2024-11-14T03:54:56","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5448\/"},"modified":"2024-11-14T11:54:56","modified_gmt":"2024-11-14T03:54:56","slug":"mysql%e6%80%8e%e4%b9%88%e7%bb%99%e7%94%a8%e6%88%b7%e6%8e%88%e6%9d%83","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5448\/","title":{"rendered":"mysql\u600e\u4e48\u7ed9\u7528\u6237\u6388\u6743"},"content":{"rendered":"<blockquote><p>\n  \u6388\u4e88 mysql \u7528\u6237\u6388\u6743\u7684\u6b65\u9aa4\uff1a\u8fde\u63a5\u5230\u6570\u636e\u5e93\u5e76\u521b\u5efa\u7528\u6237\u3002\u4f7f\u7528 grant \u547d\u4ee4\u6388\u4e88\u6743\u9650\uff0c\u6307\u5b9a\u6743\u9650\u3001\u6570\u636e\u5e93\u540d\u3001\u8868\u540d\u548c\u7528\u6237\u540d\u3002\u5237\u65b0\u6743\u9650\u8868\u4ee5\u4f7f\u66f4\u6539\u751f\u6548\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/28\/2024052813512478631.jpg\" class=\"aligncenter\" title=\"mysql\u600e\u4e48\u7ed9\u7528\u6237\u6388\u6743\u63d2\u56fe\" alt=\"mysql\u600e\u4e48\u7ed9\u7528\u6237\u6388\u6743\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u7ed9 MySQL \u7528\u6237\u6388\u6743<\/strong><\/p>\n<p>\u6388\u4e88\u7528\u6237\u5728 MySQL \u4e2d\u6267\u884c\u7279\u5b9a\u64cd\u4f5c\u7684\u6743\u9650\u662f\u6570\u636e\u5e93\u7ba1\u7406\u7684\u91cd\u8981\u65b9\u9762\u3002\u4ee5\u4e0b\u662f\u6388\u4e88\u7528\u6237\u6388\u6743\u7684\u5206\u6b65\u6307\u5357\uff1a<\/p>\n<p><strong>1. \u8fde\u63a5\u5230 MySQL \u6570\u636e\u5e93<\/strong><\/p>\n<p>\u4f7f\u7528\u60a8\u6709\u6743\u8bbf\u95ee\u8be5\u6570\u636e\u5e93\u7684\u51ed\u636e\u8fde\u63a5\u5230 MySQL \u6570\u636e\u5e93\u3002<\/p>\n<p><strong>2. \u521b\u5efa\u7528\u6237<\/strong><\/p>\n<p>\u5982\u679c\u60a8\u5c1a\u672a\u4e3a\u8981\u6388\u4e88\u6743\u9650\u7684\u7528\u6237\u521b\u5efa\u7528\u6237\uff0c\u8bf7\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u521b\u5efa\uff1a<\/p>\n<pre>CREATE USER 'username'@'hostname' IDENTIFIED BY 'password';<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5176\u4e2d\uff1a<\/p>\n<ul>\n<li>username\u662f\u8981\u521b\u5efa\u7684\u7528\u6237\u7684\u7528\u6237\u540d\u3002<\/li>\n<li>hostname\u662f\u7528\u6237\u53ef\u4ee5\u4ece\u5176\u8fde\u63a5\u7684\u4e3b\u673a\u540d\uff08\u6216 % \u4ee5\u5141\u8bb8\u4ece\u4efb\u4f55\u4e3b\u673a\u8fde\u63a5\uff09\u3002<\/li>\n<li>password\u662f\u7528\u6237\u7684\u5bc6\u7801\u3002<\/li>\n<\/ul>\n<p><strong>3. \u6388\u4e88\u6743\u9650<\/strong><\/p>\n<p>\u8981\u6388\u4e88\u7528\u6237\u6743\u9650\uff0c\u8bf7\u4f7f\u7528 GRANT \u547d\u4ee4\u3002\u8bed\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre>GRANT &lt;\u6743\u9650&gt; ON &lt;\u6570\u636e\u5e93\u540d&gt;.&lt;\u8868\u540d&gt; TO 'username'@'hostname';<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5176\u4e2d\uff1a<\/p>\n<ul>\n<li>\u662f\u8981\u6388\u4e88\u7684\u6743\u9650\uff08\u4f8b\u5982 SELECT, INSERT, UPDATE, DELETE\uff09\u3002<\/li>\n<li>\u662f\u6388\u4e88\u6743\u9650\u7684\u6570\u636e\u5e93\u540d\u79f0\u3002<\/li>\n<li>\u662f\u6388\u4e88\u6743\u9650\u7684\u8868\u540d\u79f0\uff08\u6216 * \u4ee5\u6388\u4e88\u5bf9\u8be5\u6570\u636e\u5e93\u4e2d\u7684\u6240\u6709\u8868\u7684\u6743\u9650\uff09\u3002<\/li>\n<\/ul>\n<p><strong>4. \u5237\u65b0\u6743\u9650<\/strong><\/p>\n<p>\u5728\u6388\u4e88\u6743\u9650\u540e\uff0c\u5fc5\u987b\u5237\u65b0\u6743\u9650\u8868\u4ee5\u4f7f\u66f4\u6539\u751f\u6548\u3002\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5237\u65b0\u6743\u9650\uff1a<\/p>\n<pre>FLUSH PRIVILEGES;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<p>\u8981\u6388\u4e88\u7528\u6237 john \u5728 mydatabase \u6570\u636e\u5e93\u4e2d\u7684 users \u8868\u4e0a\u5177\u6709 SELECT \u548c INSERT \u6743\u9650\uff0c\u8bf7\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre>GRANT SELECT, INSERT ON mydatabase.users TO 'john'@'%';\nFLUSH PRIVILEGES;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u73b0\u5728\uff0c\u7528\u6237 john \u5c06\u80fd\u591f\u4ece\u4efb\u4f55\u4e3b\u673a\u8fde\u63a5\u5e76\u6267\u884c SELECT \u548c INSERT \u64cd\u4f5c\uff0c\u800c\u5bf9\u8be5\u6570\u636e\u5e93\u4e2d\u7684\u5176\u4ed6\u8868\u6ca1\u6709\u8bbf\u95ee\u6743\u9650\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u600e\u4e48\u7ed9\u7528\u6237\u6388\u6743\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>\u6388\u4e88 mysql \u7528\u6237\u6388\u6743\u7684\u6b65\u9aa4\uff1a\u8fde\u63a5\u5230\u6570\u636e\u5e93\u5e76\u521b\u5efa\u7528\u6237\u3002\u4f7f\u7528 grant \u547d\u4ee4\u6388\u4e88\u6743\u9650\uff0c\u6307\u5b9a\u6743\u9650\u3001\u6570\u636e\u5e93\u540d\u3001\u8868\u540d\u548c\u7528\u6237\u540d\u3002\u5237\u65b0\u6743\u9650\u8868\u4ee5\u4f7f\u66f4\u6539\u751f\u6548\u3002 \u5982\u4f55\u7ed9 MySQL \u7528\u6237\u6388\u6743 \u6388\u4e88\u7528\u6237\u5728 MySQL \u4e2d\u6267\u884c\u7279\u5b9a\u64cd\u4f5c\u7684\u6743\u9650\u662f\u6570\u636e\u5e93\u7ba1\u7406\u7684\u91cd\u8981\u65b9\u9762\u3002\u4ee5\u4e0b\u662f\u6388\u4e88\u7528\u6237\u6388\u6743\u7684\u5206\u6b65\u6307\u5357\uff1a 1. \u8fde\u63a5\u5230 MySQL \u6570\u636e\u5e93 \u4f7f\u7528\u60a8\u6709\u6743\u8bbf\u95ee\u8be5\u6570\u636e\u5e93\u7684\u51ed\u636e\u8fde\u63a5\u5230 MySQL \u6570\u636e\u5e93\u3002 2. \u521b\u5efa\u7528\u6237 \u5982\u679c\u60a8\u5c1a\u672a\u4e3a\u8981\u6388\u4e88\u6743\u9650\u7684\u7528\u6237\u521b\u5efa\u7528\u6237\uff0c\u8bf7\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u521b\u5efa\uff1a CREATE USER &#8216;username&#8217;@&#8217;hostname&#8217; IDENTIFIED BY &#8216;password&#8217;; \u767b\u5f55\u540e\u590d\u5236 \u5176\u4e2d\uff1a username\u662f\u8981\u521b\u5efa\u7684\u7528\u6237\u7684\u7528\u6237\u540d\u3002 hostname\u662f\u7528\u6237\u53ef\u4ee5\u4ece\u5176\u8fde\u63a5\u7684\u4e3b\u673a\u540d\uff08\u6216 % \u4ee5\u5141\u8bb8\u4ece\u4efb\u4f55\u4e3b\u673a\u8fde\u63a5\uff09\u3002 password\u662f\u7528\u6237\u7684\u5bc6\u7801\u3002 3. \u6388\u4e88\u6743\u9650 \u8981\u6388\u4e88\u7528\u6237\u6743\u9650\uff0c\u8bf7\u4f7f\u7528 GRANT \u547d\u4ee4\u3002\u8bed\u6cd5\u5982\u4e0b\uff1a GRANT &lt;\u6743\u9650&gt; ON &lt;\u6570\u636e\u5e93\u540d&gt;.&lt;\u8868\u540d&gt; TO &#8216;username&#8217;@&#8217;hostname&#8217;; \u767b\u5f55\u540e\u590d\u5236 \u5176\u4e2d\uff1a \u662f\u8981\u6388\u4e88\u7684\u6743\u9650\uff08\u4f8b\u5982 SELECT, INSERT, UPDATE, DELETE\uff09\u3002 \u662f\u6388\u4e88\u6743\u9650\u7684\u6570\u636e\u5e93\u540d\u79f0\u3002 \u662f\u6388\u4e88\u6743\u9650\u7684\u8868\u540d\u79f0\uff08\u6216 * [&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-5448","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5448","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=5448"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5448\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5448"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5448"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5448"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}