{"id":5131,"date":"2024-11-14T08:11:41","date_gmt":"2024-11-14T00:11:41","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5131\/"},"modified":"2024-11-14T08:11:41","modified_gmt":"2024-11-14T00:11:41","slug":"mysql%e6%80%8e%e4%b9%88%e6%b7%bb%e5%8a%a0%e7%94%a8%e6%88%b7","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5131\/","title":{"rendered":"mysql\u600e\u4e48\u6dfb\u52a0\u7528\u6237"},"content":{"rendered":"<blockquote><p>\n  \u8981\u4f7f\u7528 mysql \u6dfb\u52a0\u7528\u6237\uff0c\u8bf7\u6309\u4ee5\u4e0b\u6b65\u9aa4\u64cd\u4f5c\uff1a\u767b\u5f55 mysql\u3002\u4f7f\u7528 create user \u8bed\u53e5\u521b\u5efa\u65b0\u7528\u6237\u3002\uff08\u53ef\u9009\uff09\u4f7f\u7528 grant \u8bed\u53e5\u6388\u4e88\u7528\u6237\u6743\u9650\u3002\u5237\u65b0\u6743\u9650\u4ee5\u5e94\u7528\u66f4\u6539\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/22\/2024052215303250794.jpg\" class=\"aligncenter\" title=\"mysql\u600e\u4e48\u6dfb\u52a0\u7528\u6237\u63d2\u56fe\" alt=\"mysql\u600e\u4e48\u6dfb\u52a0\u7528\u6237\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u4f7f\u7528 MySQL \u6dfb\u52a0\u7528\u6237<\/strong><\/p>\n<p><strong>\u6b65\u9aa4 1\uff1a\u767b\u5f55 MySQL<\/strong><\/p>\n<p>\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u767b\u5f55\u5230 MySQL\uff1a<\/p>\n<pre>mysql -u root -p<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6b65\u9aa4 2\uff1a\u521b\u5efa\u65b0\u7528\u6237<\/strong><\/p>\n<p>\u4f7f\u7528 CREATE USER \u8bed\u53e5\u521b\u5efa\u65b0\u7528\u6237\u3002\u8bed\u6cd5\u5982\u4e0b\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\u65b0\u7528\u6237\u7684\u540d\u79f0\u3002<\/li>\n<li>hostname \u6307\u5b9a\u7528\u6237\u53ef\u4ee5\u4ece\u54ea\u4e9b\u4e3b\u673a\u8fde\u63a5\u3002\u53ef\u4ee5\u5c06 % \u7528\u4f5c\u901a\u914d\u7b26\u4ee5\u5141\u8bb8\u4ece\u4efb\u4f55\u4e3b\u673a\u8fdb\u884c\u8fde\u63a5\u3002<\/li>\n<li>password \u662f\u7528\u6237\u5bc6\u7801\u3002<\/li>\n<\/ul>\n<p>\u4f8b\u5982\uff0c\u8981\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a newuser \u7684\u65b0\u7528\u6237\uff0c\u8be5\u7528\u6237\u53ef\u4ee5\u4ece\u4efb\u4f55\u4e3b\u673a\u8fde\u63a5\u5e76\u4f7f\u7528\u5bc6\u7801 secret\uff0c\u8bf7\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre>CREATE USER 'newuser'@'%' IDENTIFIED BY 'secret';<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6b65\u9aa4 3\uff1a\u6388\u4e88\u6743\u9650 (\u53ef\u9009)<\/strong><\/p>\n<p>\u60a8\u53ef\u4ee5\u4f7f\u7528 GRANT \u8bed\u53e5\u6388\u4e88\u65b0\u7528\u6237\u5bf9\u7279\u5b9a\u6570\u636e\u5e93\u6216\u8868\u7684\u6743\u9650\u3002\u8bed\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre>GRANT &lt;permission&gt; ON &lt;database_or_table&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\uff0c\u4f8b\u5982 SELECT\u3001INSERT\u3001UPDATE \u6216 DELETE\u3002 <\/li>\n<li> \u662f\u6570\u636e\u5e93\u6216\u8868\u540d\u79f0\u3002 <\/li>\n<li>.* \u8868\u793a\u5bf9\u6574\u4e2a\u6570\u636e\u5e93\u6216\u8868\u6388\u4e88\u6743\u9650\u3002<\/li>\n<\/ul>\n<p>\u4f8b\u5982\uff0c\u8981\u6388\u4e88 newuser \u5bf9 mydb \u6570\u636e\u5e93\u7684\u6240\u6709\u6743\u9650\uff0c\u8bf7\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre>GRANT ALL ON mydb.* TO 'newuser'@'%';<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6b65\u9aa4 4\uff1a\u5237\u65b0\u6743\u9650<\/strong><\/p>\n<p>\u5237\u65b0\u6743\u9650\u4ee5\u786e\u4fdd MySQL \u7acb\u5373\u5c06\u66f4\u6539\u5e94\u7528\u5230\u65b0\u7528\u6237\u3002\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre>FLUSH PRIVILEGES;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u600e\u4e48\u6dfb\u52a0\u7528\u6237\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>\u8981\u4f7f\u7528 mysql \u6dfb\u52a0\u7528\u6237\uff0c\u8bf7\u6309\u4ee5\u4e0b\u6b65\u9aa4\u64cd\u4f5c\uff1a\u767b\u5f55 mysql\u3002\u4f7f\u7528 create user \u8bed\u53e5\u521b\u5efa\u65b0\u7528\u6237\u3002\uff08\u53ef\u9009\uff09\u4f7f\u7528 grant \u8bed\u53e5\u6388\u4e88\u7528\u6237\u6743\u9650\u3002\u5237\u65b0\u6743\u9650\u4ee5\u5e94\u7528\u66f4\u6539\u3002 \u5982\u4f55\u4f7f\u7528 MySQL \u6dfb\u52a0\u7528\u6237 \u6b65\u9aa4 1\uff1a\u767b\u5f55 MySQL \u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u767b\u5f55\u5230 MySQL\uff1a mysql -u root -p \u767b\u5f55\u540e\u590d\u5236 \u6b65\u9aa4 2\uff1a\u521b\u5efa\u65b0\u7528\u6237 \u4f7f\u7528 CREATE USER \u8bed\u53e5\u521b\u5efa\u65b0\u7528\u6237\u3002\u8bed\u6cd5\u5982\u4e0b\uff1a CREATE USER &#8216;username&#8217;@&#8217;hostname&#8217; IDENTIFIED BY &#8216;password&#8217;; \u767b\u5f55\u540e\u590d\u5236 \u5176\u4e2d\uff1a username \u662f\u65b0\u7528\u6237\u7684\u540d\u79f0\u3002 hostname \u6307\u5b9a\u7528\u6237\u53ef\u4ee5\u4ece\u54ea\u4e9b\u4e3b\u673a\u8fde\u63a5\u3002\u53ef\u4ee5\u5c06 % \u7528\u4f5c\u901a\u914d\u7b26\u4ee5\u5141\u8bb8\u4ece\u4efb\u4f55\u4e3b\u673a\u8fdb\u884c\u8fde\u63a5\u3002 password \u662f\u7528\u6237\u5bc6\u7801\u3002 \u4f8b\u5982\uff0c\u8981\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a newuser \u7684\u65b0\u7528\u6237\uff0c\u8be5\u7528\u6237\u53ef\u4ee5\u4ece\u4efb\u4f55\u4e3b\u673a\u8fde\u63a5\u5e76\u4f7f\u7528\u5bc6\u7801 secret\uff0c\u8bf7\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a CREATE USER &#8216;newuser&#8217;@&#8217;%&#8217; IDENTIFIED BY &#8216;secret&#8217;; \u767b\u5f55\u540e\u590d\u5236 [&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-5131","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5131","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=5131"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5131\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5131"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5131"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5131"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}