{"id":6236,"date":"2024-11-14T09:25:55","date_gmt":"2024-11-14T01:25:55","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6236\/"},"modified":"2024-11-14T09:25:55","modified_gmt":"2024-11-14T01:25:55","slug":"mysql%e5%a6%82%e4%bd%95%e8%ae%be%e7%bd%ae%e5%a4%9a%e7%94%a8%e6%88%b7%e5%a4%9a%e8%b4%a6%e5%8f%b7","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/6236\/","title":{"rendered":"mysql\u5982\u4f55\u8bbe\u7f6e\u591a\u7528\u6237\u591a\u8d26\u53f7"},"content":{"rendered":"<blockquote><p>\n  \u5982\u4f55\u8bbe\u7f6e mysql \u591a\u7528\u6237\u591a\u8d26\u53f7\uff1f\u521b\u5efa\u7528\u6237\u5e10\u6237\uff0c\u6307\u5b9a\u7528\u6237\u540d\u3001\u4e3b\u673a\u540d\u548c\u5bc6\u7801\u3002\u6388\u4e88\u7528\u6237\u5bf9\u7279\u5b9a\u6570\u636e\u5e93\u7684\u6240\u9700\u6743\u9650\uff0c\u5305\u62ec\u6743\u9650\u7c7b\u578b\u548c\u6570\u636e\u5e93\u540d\u79f0\u3002\u5237\u65b0\u6743\u9650\uff0c\u4f7f\u66f4\u6539\u751f\u6548\u3002\u4f7f\u7528\u7528\u6237\u540d\u3001\u4e3b\u673a\u540d\u3001\u5bc6\u7801\u548c\u670d\u52a1\u5668\u4e3b\u673a\u540d\uff0c\u8fde\u63a5\u5230\u6570\u636e\u5e93\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202406\/15\/2024061515392467052.jpg\" class=\"aligncenter\" title=\"mysql\u5982\u4f55\u8bbe\u7f6e\u591a\u7528\u6237\u591a\u8d26\u53f7\u63d2\u56fe\" alt=\"mysql\u5982\u4f55\u8bbe\u7f6e\u591a\u7528\u6237\u591a\u8d26\u53f7\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u8bbe\u7f6e MySQL \u591a\u7528\u6237\u591a\u8d26\u53f7<\/strong><\/p>\n<p>\u8981\u8bbe\u7f6e MySQL \u591a\u7528\u6237\u591a\u8d26\u53f7\uff0c\u9700\u8981\u9075\u5faa\u4ee5\u4e0b\u6b65\u9aa4\uff1a<\/p>\n<p><strong>1. \u521b\u5efa\u7528\u6237\u5e10\u6237<\/strong><\/p>\n<p>\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u521b\u5efa\u7528\u6237\u5e10\u6237\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 \u662f\u5141\u8bb8\u7528\u6237\u8fde\u63a5\u7684\u670d\u52a1\u5668\u540d\u79f0\uff08% \u8868\u793a\u4ece\u4efb\u4f55\u4e3b\u673a\uff09\u3002<\/li>\n<li>password \u662f\u7528\u6237\u7684\u5bc6\u7801\u3002<\/li>\n<\/ul>\n<p><strong>2. \u6388\u4e88\u6743\u9650<\/strong><\/p>\n<p>\u521b\u5efa\u7528\u6237\u540e\uff0c\u9700\u8981\u6388\u4e88\u9002\u5f53\u7684\u6743\u9650\u624d\u80fd\u8bbf\u95ee\u6570\u636e\u5e93\uff1a<\/p>\n<pre>GRANT &lt;\u6743\u9650\u5217\u8868&gt; ON &lt;\u6570\u636e\u5e93\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\u5217\u8868\uff08\u4f8b\u5982 SELECT\u3001INSERT\uff09\u3002<\/li>\n<li> \u662f\u8981\u6388\u4e88\u6743\u9650\u7684\u6570\u636e\u5e93\u540d\u79f0\u3002<\/li>\n<\/ul>\n<p><strong>3. \u5237\u65b0\u6743\u9650<\/strong><\/p>\n<p>\u66f4\u6539\u5b8c\u6210\u540e\uff0c\u9700\u8981\u5237\u65b0\u6743\u9650\u624d\u80fd\u7acb\u5373\u751f\u6548\uff1a<\/p>\n<pre>FLUSH PRIVILEGES;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>4. \u8fde\u63a5\u5230\u6570\u636e\u5e93<\/strong><\/p>\n<p>\u73b0\u5728\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fde\u63a5\u5230\u6570\u636e\u5e93\uff1a<\/p>\n<pre>mysql -u username -p password -h hostname<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5176\u4e2d\uff1a<\/p>\n<ul>\n<li>-u \u6307\u5b9a\u7528\u6237\u540d\u3002<\/li>\n<li>-p \u8981\u6c42\u8f93\u5165\u5bc6\u7801\u3002<\/li>\n<li>-h \u6307\u5b9a\u670d\u52a1\u5668\u4e3b\u673a\u540d\u3002<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b<\/strong><\/p>\n<p>\u4ee5\u4e0b\u793a\u4f8b\u521b\u5efa\u4e86\u4e00\u4e2a\u540d\u4e3a newuser \u7684\u7528\u6237\uff0c\u5e76\u6388\u4e88\u5176\u5bf9 mydb \u6570\u636e\u5e93\u7684 SELECT \u548c INSERT \u6743\u9650\uff1a<\/p>\n<pre>CREATE USER 'newuser'@'%' IDENTIFIED BY 'mypassword';\nGRANT SELECT, INSERT ON `mydb`.* TO 'newuser'@'%';\nFLUSH PRIVILEGES;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u73b0\u5728\uff0c\u7528\u6237 newuser \u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u8fde\u63a5\u5230\u6570\u636e\u5e93\uff1a<\/p>\n<pre>mysql -u newuser -p mypassword -h localhost<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u8bbe\u7f6e\u591a\u7528\u6237\u591a\u8d26\u53f7\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>\u5982\u4f55\u8bbe\u7f6e mysql \u591a\u7528\u6237\u591a\u8d26\u53f7\uff1f\u521b\u5efa\u7528\u6237\u5e10\u6237\uff0c\u6307\u5b9a\u7528\u6237\u540d\u3001\u4e3b\u673a\u540d\u548c\u5bc6\u7801\u3002\u6388\u4e88\u7528\u6237\u5bf9\u7279\u5b9a\u6570\u636e\u5e93\u7684\u6240\u9700\u6743\u9650\uff0c\u5305\u62ec\u6743\u9650\u7c7b\u578b\u548c\u6570\u636e\u5e93\u540d\u79f0\u3002\u5237\u65b0\u6743\u9650\uff0c\u4f7f\u66f4\u6539\u751f\u6548\u3002\u4f7f\u7528\u7528\u6237\u540d\u3001\u4e3b\u673a\u540d\u3001\u5bc6\u7801\u548c\u670d\u52a1\u5668\u4e3b\u673a\u540d\uff0c\u8fde\u63a5\u5230\u6570\u636e\u5e93\u3002 \u5982\u4f55\u8bbe\u7f6e MySQL \u591a\u7528\u6237\u591a\u8d26\u53f7 \u8981\u8bbe\u7f6e MySQL \u591a\u7528\u6237\u591a\u8d26\u53f7\uff0c\u9700\u8981\u9075\u5faa\u4ee5\u4e0b\u6b65\u9aa4\uff1a 1. \u521b\u5efa\u7528\u6237\u5e10\u6237 \u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u521b\u5efa\u7528\u6237\u5e10\u6237\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 \u662f\u5141\u8bb8\u7528\u6237\u8fde\u63a5\u7684\u670d\u52a1\u5668\u540d\u79f0\uff08% \u8868\u793a\u4ece\u4efb\u4f55\u4e3b\u673a\uff09\u3002 password \u662f\u7528\u6237\u7684\u5bc6\u7801\u3002 2. \u6388\u4e88\u6743\u9650 \u521b\u5efa\u7528\u6237\u540e\uff0c\u9700\u8981\u6388\u4e88\u9002\u5f53\u7684\u6743\u9650\u624d\u80fd\u8bbf\u95ee\u6570\u636e\u5e93\uff1a GRANT &lt;\u6743\u9650\u5217\u8868&gt; ON &lt;\u6570\u636e\u5e93\u540d&gt;.* TO &#8216;username&#8217;@&#8217;hostname&#8217;; \u767b\u5f55\u540e\u590d\u5236 \u5176\u4e2d\uff1a \u662f\u8981\u6388\u4e88\u7684\u6743\u9650\u5217\u8868\uff08\u4f8b\u5982 SELECT\u3001INSERT\uff09\u3002 \u662f\u8981\u6388\u4e88\u6743\u9650\u7684\u6570\u636e\u5e93\u540d\u79f0\u3002 3. \u5237\u65b0\u6743\u9650 \u66f4\u6539\u5b8c\u6210\u540e\uff0c\u9700\u8981\u5237\u65b0\u6743\u9650\u624d\u80fd\u7acb\u5373\u751f\u6548\uff1a FLUSH PRIVILEGES; \u767b\u5f55\u540e\u590d\u5236 4. \u8fde\u63a5\u5230\u6570\u636e\u5e93 \u73b0\u5728\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fde\u63a5\u5230\u6570\u636e\u5e93\uff1a mysql -u username -p password [&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-6236","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6236","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=6236"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6236\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6236"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6236"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6236"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}