{"id":6253,"date":"2024-11-14T08:47:35","date_gmt":"2024-11-14T00:47:35","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6253\/"},"modified":"2024-11-14T08:47:35","modified_gmt":"2024-11-14T00:47:35","slug":"mysql%e5%a6%82%e4%bd%95%e5%8a%a0%e6%9d%83%e9%99%90","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/6253\/","title":{"rendered":"mysql\u5982\u4f55\u52a0\u6743\u9650"},"content":{"rendered":"<blockquote><p>\n  \u8981\u4e3a mysql \u7528\u6237\u6388\u4e88\u6743\u9650\uff0c\u8bf7\u6267\u884c\u4ee5\u4e0b\u6b65\u9aa4\uff1a\u8fde\u63a5\u5230 mysql \u670d\u52a1\u5668\uff08\u4f7f\u7528\u8d85\u7ea7\u7528\u6237\u51ed\u8bc1\uff09\u3002\u521b\u5efa\u65b0\u7528\u6237\u3002\u6388\u4e88\u65b0\u7528\u6237\u7279\u5b9a\u6570\u636e\u5e93\u6216\u8868\u7684\u6743\u9650\uff08select\u3001insert\u3001update\u3001delete\uff09\u3002\u5237\u65b0\u6743\u9650\u8868\u3002\u9000\u51fa\u5e76\u91cd\u65b0\u8fde\u63a5\u4ee5\u9a8c\u8bc1\u6743\u9650\u3002\u6d4b\u8bd5\u8bbf\u95ee\uff08\u4f7f\u7528\u65b0\u7528\u6237\u51ed\u8bc1\uff09\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202406\/15\/2024061517005311992.jpg\" class=\"aligncenter\" title=\"mysql\u5982\u4f55\u52a0\u6743\u9650\u63d2\u56fe\" alt=\"mysql\u5982\u4f55\u52a0\u6743\u9650\u63d2\u56fe\" \/><\/p>\n<p><strong>\u6559\u7a0b\uff1a\u4e3a MySQL \u6570\u636e\u5e93\u7528\u6237\u6388\u4e88\u6743\u9650<\/strong><\/p>\n<p><strong>\u5982\u4f55\u4e3a MySQL \u6570\u636e\u5e93\u7528\u6237\u6388\u4e88\u6743\u9650\uff1f<\/strong><\/p>\n<p>\u6388\u4e88 MySQL \u6570\u636e\u5e93\u7528\u6237\u6743\u9650\u662f\u4e00\u4e2a\u5173\u952e\u7684\u5b89\u5168\u6b65\u9aa4\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u5b9e\u73b0\uff1a<\/p>\n<p><strong>1. \u8fde\u63a5\u5230 MySQL \u670d\u52a1\u5668<\/strong><\/p>\n<p>\u4f7f\u7528\u201c -u root -p\u201d\u547d\u4ee4\u8fde\u63a5\u5230 MySQL \u670d\u52a1\u5668\uff0c\u5176\u4e2d\u201croot\u201d\u662f\u5177\u6709\u8d85\u7ea7\u7528\u6237\u6743\u9650\u7684\u9ed8\u8ba4\u7528\u6237\u540d\uff0c\u201c-p\u201d\u6807\u5fd7\u8981\u6c42\u8f93\u5165 root \u7528\u6237\u7684\u5bc6\u7801\u3002<\/p>\n<p><strong>2. \u521b\u5efa\u65b0\u7528\u6237<\/strong><\/p>\n<p>\u4f7f\u7528\u201cCREATE USER\u201d\u547d\u4ee4\u521b\u5efa\u4e00\u4e2a\u65b0\u7528\u6237\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre>CREATE USER 'new_user'@'localhost' IDENTIFIED BY 'password';<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5176\u4e2d\u201cnew_user\u201d\u662f\u65b0\u7528\u6237\u7684\u540d\u79f0\uff0c\u201clocalhost\u201d\u6307\u5b9a\u7528\u6237\u53ea\u80fd\u4ece\u672c\u5730\u4e3b\u673a\u8fde\u63a5\uff0c\u800c\u201cpassword\u201d\u662f\u65b0\u7528\u6237\u7684\u5bc6\u7801\u3002<\/p>\n<p><strong>3. \u6388\u4e88\u6743\u9650<\/strong><\/p>\n<p>\u4f7f\u7528\u201cGRANT\u201d\u547d\u4ee4\u6388\u4e88\u65b0\u7528\u6237\u7279\u5b9a\u6570\u636e\u5e93\u6216\u8868\u7684\u6743\u9650\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre>GRANT SELECT, INSERT, UPDATE, DELETE ON database_name.* TO 'new_user'@'localhost';<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5176\u4e2d\uff1a<\/p>\n<ul>\n<li>SELECT\uff1a\u5141\u8bb8\u7528\u6237\u4ece\u6307\u5b9a\u6570\u636e\u5e93\u4e2d\u68c0\u7d22\u6570\u636e<\/li>\n<li>INSERT\uff1a\u5141\u8bb8\u7528\u6237\u5411\u6307\u5b9a\u6570\u636e\u5e93\u63d2\u5165\u6570\u636e<\/li>\n<li>UPDATE\uff1a\u5141\u8bb8\u7528\u6237\u66f4\u65b0\u6307\u5b9a\u6570\u636e\u5e93\u4e2d\u7684\u6570\u636e<\/li>\n<li>DELETE\uff1a\u5141\u8bb8\u7528\u6237\u4ece\u6307\u5b9a\u6570\u636e\u5e93\u4e2d\u5220\u9664\u6570\u636e<\/li>\n<\/ul>\n<p><strong>4. \u5237\u65b0\u6743\u9650<\/strong><\/p>\n<p>\u5728\u6388\u4e88\u6743\u9650\u540e\uff0c\u4f7f\u7528\u201cFLUSH PRIVILEGES\u201d\u547d\u4ee4\u5237\u65b0\u6743\u9650\u8868\uff0c\u4f7f\u65b0\u6743\u9650\u751f\u6548\u3002<\/p>\n<p><strong>5. \u9000\u51fa\u5e76\u91cd\u65b0\u8fde\u63a5<\/strong><\/p>\n<p>\u9000\u51fa MySQL \u670d\u52a1\u5668\u5e76\u91cd\u65b0\u8fde\u63a5\u4ee5\u9a8c\u8bc1\u65b0\u6743\u9650\u3002<\/p>\n<p><strong>6. \u6d4b\u8bd5\u8bbf\u95ee<\/strong><\/p>\n<p>\u4f7f\u7528\u65b0\u7528\u6237\u51ed\u8bc1\u767b\u5f55\u5e76\u6267\u884c\u67e5\u8be2\u4ee5\u6d4b\u8bd5\u6743\u9650\u662f\u5426\u5df2\u6b63\u786e\u6388\u4e88\u3002<\/p>\n<p><strong>\u63d0\u793a\uff1a<\/strong><\/p>\n<ul>\n<li>\u4ec5\u6388\u4e88\u7528\u6237\u7edd\u5bf9\u5fc5\u8981\u7684\u6743\u9650\uff0c\u4ee5\u6700\u5c0f\u5316\u5b89\u5168\u98ce\u9669\u3002<\/li>\n<li>\u4f7f\u7528\u5f3a\u5bc6\u7801\u5e76\u5b9a\u671f\u66f4\u6539\u5bc6\u7801\u3002<\/li>\n<li>\u8003\u8651\u4f7f\u7528\u89d2\u8272\u6765\u7ba1\u7406\u6743\u9650\u5e76\u7b80\u5316\u7ba1\u7406\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u52a0\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>\u8981\u4e3a mysql \u7528\u6237\u6388\u4e88\u6743\u9650\uff0c\u8bf7\u6267\u884c\u4ee5\u4e0b\u6b65\u9aa4\uff1a\u8fde\u63a5\u5230 mysql \u670d\u52a1\u5668\uff08\u4f7f\u7528\u8d85\u7ea7\u7528\u6237\u51ed\u8bc1\uff09\u3002\u521b\u5efa\u65b0\u7528\u6237\u3002\u6388\u4e88\u65b0\u7528\u6237\u7279\u5b9a\u6570\u636e\u5e93\u6216\u8868\u7684\u6743\u9650\uff08select\u3001insert\u3001update\u3001delete\uff09\u3002\u5237\u65b0\u6743\u9650\u8868\u3002\u9000\u51fa\u5e76\u91cd\u65b0\u8fde\u63a5\u4ee5\u9a8c\u8bc1\u6743\u9650\u3002\u6d4b\u8bd5\u8bbf\u95ee\uff08\u4f7f\u7528\u65b0\u7528\u6237\u51ed\u8bc1\uff09\u3002 \u6559\u7a0b\uff1a\u4e3a MySQL \u6570\u636e\u5e93\u7528\u6237\u6388\u4e88\u6743\u9650 \u5982\u4f55\u4e3a MySQL \u6570\u636e\u5e93\u7528\u6237\u6388\u4e88\u6743\u9650\uff1f \u6388\u4e88 MySQL \u6570\u636e\u5e93\u7528\u6237\u6743\u9650\u662f\u4e00\u4e2a\u5173\u952e\u7684\u5b89\u5168\u6b65\u9aa4\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u5b9e\u73b0\uff1a 1. \u8fde\u63a5\u5230 MySQL \u670d\u52a1\u5668 \u4f7f\u7528\u201c -u root -p\u201d\u547d\u4ee4\u8fde\u63a5\u5230 MySQL \u670d\u52a1\u5668\uff0c\u5176\u4e2d\u201croot\u201d\u662f\u5177\u6709\u8d85\u7ea7\u7528\u6237\u6743\u9650\u7684\u9ed8\u8ba4\u7528\u6237\u540d\uff0c\u201c-p\u201d\u6807\u5fd7\u8981\u6c42\u8f93\u5165 root \u7528\u6237\u7684\u5bc6\u7801\u3002 2. \u521b\u5efa\u65b0\u7528\u6237 \u4f7f\u7528\u201cCREATE USER\u201d\u547d\u4ee4\u521b\u5efa\u4e00\u4e2a\u65b0\u7528\u6237\uff0c\u4f8b\u5982\uff1a CREATE USER &#8216;new_user&#8217;@&#8217;localhost&#8217; IDENTIFIED BY &#8216;password&#8217;; \u767b\u5f55\u540e\u590d\u5236 \u5176\u4e2d\u201cnew_user\u201d\u662f\u65b0\u7528\u6237\u7684\u540d\u79f0\uff0c\u201clocalhost\u201d\u6307\u5b9a\u7528\u6237\u53ea\u80fd\u4ece\u672c\u5730\u4e3b\u673a\u8fde\u63a5\uff0c\u800c\u201cpassword\u201d\u662f\u65b0\u7528\u6237\u7684\u5bc6\u7801\u3002 3. \u6388\u4e88\u6743\u9650 \u4f7f\u7528\u201cGRANT\u201d\u547d\u4ee4\u6388\u4e88\u65b0\u7528\u6237\u7279\u5b9a\u6570\u636e\u5e93\u6216\u8868\u7684\u6743\u9650\uff0c\u4f8b\u5982\uff1a GRANT SELECT, INSERT, UPDATE, DELETE ON database_name.* TO &#8216;new_user&#8217;@&#8217;localhost&#8217;; \u767b\u5f55\u540e\u590d\u5236 \u5176\u4e2d\uff1a SELECT\uff1a\u5141\u8bb8\u7528\u6237\u4ece\u6307\u5b9a\u6570\u636e\u5e93\u4e2d\u68c0\u7d22\u6570\u636e INSERT\uff1a\u5141\u8bb8\u7528\u6237\u5411\u6307\u5b9a\u6570\u636e\u5e93\u63d2\u5165\u6570\u636e UPDATE\uff1a\u5141\u8bb8\u7528\u6237\u66f4\u65b0\u6307\u5b9a\u6570\u636e\u5e93\u4e2d\u7684\u6570\u636e [&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-6253","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6253","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=6253"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6253\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6253"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6253"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6253"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}