{"id":260,"date":"2024-06-19T16:49:54","date_gmt":"2024-06-19T08:49:54","guid":{"rendered":"http:\/\/zhaoyanqi.cn\/?p=260"},"modified":"2024-06-19T18:17:12","modified_gmt":"2024-06-19T10:17:12","slug":"260","status":"publish","type":"post","link":"https:\/\/zhaoyanqi.cn\/?p=260","title":{"rendered":"\u5b9e\u9a8c\uff1aMySQL\u6570\u636e\u5e93\u7528\u6237\u548c\u6743\u9650\u7ba1\u7406"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\" id=\"DWoQA\">1. \u521b\u5efa\u5e93 <code>db1<\/code> \u548c\u7528\u6237\u8868 <code>t1<\/code><\/h2>\n\n\n\n<p id=\"u97be72e8\">\u9996\u5148\uff0c\u521b\u5efa\u6570\u636e\u5e93 <code>db1<\/code>\uff0c\u5e76\u5728\u5176\u4e2d\u521b\u5efa\u8868 <code>t1<\/code>\uff0c\u7136\u540e\u63d2\u516510\u6761\u8bb0\u5f55\u3002<\/p>\n\n\n\n<pre id=\"sFH61\" class=\"wp-block-code\"><code>CREATE DATABASE db1;\n\nUSE db1;\n\nCREATE TABLE t1 (\n    id INT PRIMARY KEY AUTO_INCREMENT,\n    name VARCHAR(50),\n    age INT,\n    gender ENUM('male', 'female')\n);\n\nINSERT INTO t1 (name, age, gender) VALUES\n('Alice', 25, 'female'),\n('Bob', 30, 'male'),\n('Charlie', 35, 'male'),\n('David', 40, 'male'),\n('Eve', 22, 'female'),\n('Frank', 28, 'male'),\n('Grace', 32, 'female'),\n('Heidi', 27, 'female'),\n('Ivan', 23, 'male'),\n('Judy', 29, 'female');<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"d67K8\">2. \u521b\u5efa\u8fdc\u7a0b\u8d26\u6237 <code>egon1<\/code> \u5e76\u6388\u6743<\/h2>\n\n\n\n<p id=\"u1681b974\">\u521b\u5efa\u7528\u6237 <code>egon1<\/code>\uff0c\u5e76\u6388\u4e88\u5176\u5bf9\u6240\u6709\u5e93\u4e0b\u7684\u6240\u6709\u8868\u7684\u6240\u6709\u6743\u9650\uff08\u9664\u4e86GRANT\u6743\u9650\u4e4b\u5916\uff09\u3002<\/p>\n\n\n\n<pre id=\"KrOu4\" class=\"wp-block-code\"><code>CREATE USER 'egon1'@'%' IDENTIFIED BY 'Passw@rd1';\n\nGRANT ALL PRIVILEGES ON *.* TO 'egon1'@'%';<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"umbK5\">3. \u521b\u5efa\u8fdc\u7a0b\u8d26\u6237 <code>egon2<\/code> \u5e76\u6388\u6743<\/h2>\n\n\n\n<p id=\"u3bde365b\">\u521b\u5efa\u7528\u6237 <code>egon2<\/code>\uff0c\u5e76\u6388\u4e88\u5176\u5bf9 <code>db1<\/code> \u5e93\u4e0b\u6240\u6709\u8868\u7684\u6240\u6709\u6743\u9650\uff0c\u7136\u540e\u8fdc\u7a0b\u767b\u5f55\u9a8c\u8bc1\u3002<\/p>\n\n\n\n<pre id=\"OgumB\" class=\"wp-block-code\"><code>CREATE USER 'egon2'@'%' IDENTIFIED BY 'Passw@rd2';\n\nGRANT ALL PRIVILEGES ON db1.* TO 'egon2'@'%' WITH GRANT OPTION;<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"Ohc8i\">4. \u521b\u5efa\u8fdc\u7a0b\u8d26\u6237 <code>egon3<\/code> \u5e76\u6388\u6743<\/h2>\n\n\n\n<p id=\"ue60779b0\">\u521b\u5efa\u7528\u6237 <code>egon3<\/code>\uff0c\u5e76\u6388\u4e88\u5176\u5bf9 <code>db1<\/code> \u5e93\u4e0b <code>t1<\/code> \u8868\u7684 SELECT \u6743\u9650\uff0c\u7136\u540e\u8fdc\u7a0b\u767b\u5f55\u9a8c\u8bc1\u53ea\u80fd\u770b\u5230 <code>db1<\/code> \u4e0b\u7684 <code>t1<\/code> \u8868\uff0c\u5e76\u4e14\u53ea\u80fd SELECT \u4e0d\u80fd\u505a\u5176\u4ed6\u64cd\u4f5c\u3002<\/p>\n\n\n\n<pre id=\"tFS2t\" class=\"wp-block-code\"><code>CREATE USER 'egon3'@'%' IDENTIFIED BY 'Passw@rd3';\n\nGRANT SELECT ON db1.t1 TO 'egon3'@'%';<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"yT1mp\">5. \u521b\u5efa\u8fdc\u7a0b\u8d26\u6237 <code>egon4<\/code> \u5e76\u6388\u6743<\/h2>\n\n\n\n<p id=\"ud6763334\">\u521b\u5efa\u7528\u6237 <code>egon4<\/code>\uff0c\u5e76\u6388\u4e88\u5176\u5bf9 <code>db1<\/code> \u5e93\u4e0b <code>t1<\/code> \u8868\u7684 <code>id<\/code> \u548c <code>name<\/code> \u5b57\u6bb5\u7684 SELECT \u6743\u9650\uff0c\u5bf9 <code>age<\/code> \u5b57\u6bb5\u6709 UPDATE \u6743\u9650\uff0c\u7136\u540e\u8fdc\u7a0b\u767b\u5f55\u9a8c\u8bc1\u3002<\/p>\n\n\n\n<pre id=\"QLAj2\" class=\"wp-block-code\"><code>CREATE USER 'egon4'@'%' IDENTIFIED BY 'Passw@rd4';\n\nGRANT SELECT(id, name, age), UPDATE(age) ON db1.t1 TO 'egon4'@'%';<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"gT5J5\">6. \u67e5\u51fa\u4e0a\u8ff0\u6743\u9650\u5b58\u4e8e MySQL \u4e2d\u7684\u8bb0\u5f55<\/h2>\n\n\n\n<pre id=\"ugwjm\" class=\"wp-block-code\"><code>SELECT \n    *\nFROM \n    mysql.user\nWHERE \n    user IN ('egon1', 'egon2', 'egon3', 'egon4')\\G\n\nSELECT \n    user, host, db, table_name, table_priv, column_priv \nFROM \n    mysql.tables_priv \nWHERE \n    user IN ('egon1', 'egon2', 'egon3', 'egon4');\n\nSELECT \n    user, host, db, table_name, column_name, column_priv \nFROM \n    mysql.columns_priv \nWHERE \n    user IN ('egon1', 'egon2', 'egon3', 'egon4');\n\nSELECT \n    *\nFROM \n    information_schema.user_privileges \nWHERE \n    grantee IN ('\\'egon1\\'@\\'%\\'', '\\'egon2\\'@\\'%\\'', '\\'egon3\\'@\\'%\\'', '\\'egon4\\'@\\'%\\'');\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/zhaoyanqi.cn\/wp-content\/uploads\/2024\/06\/image-46.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  loading=\"lazy\" decoding=\"async\" width=\"625\" height=\"778\" data-original=\"https:\/\/zhaoyanqi.cn\/wp-content\/uploads\/2024\/06\/image-46.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" class=\"wp-image-263\"  sizes=\"auto, (max-width: 625px) 100vw, 625px\" \/><\/div><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/zhaoyanqi.cn\/wp-content\/uploads\/2024\/06\/image-44.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  loading=\"lazy\" decoding=\"async\" width=\"682\" height=\"324\" data-original=\"https:\/\/zhaoyanqi.cn\/wp-content\/uploads\/2024\/06\/image-44.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" class=\"wp-image-261\"  sizes=\"auto, (max-width: 682px) 100vw, 682px\" \/><\/div><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/zhaoyanqi.cn\/wp-content\/uploads\/2024\/06\/image-45.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  loading=\"lazy\" decoding=\"async\" width=\"682\" height=\"326\" data-original=\"https:\/\/zhaoyanqi.cn\/wp-content\/uploads\/2024\/06\/image-45.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" class=\"wp-image-262\"  sizes=\"auto, (max-width: 682px) 100vw, 682px\" \/><\/div><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"GWkv6\">7. \u64a4\u9500\u4e0a\u8ff0\u6240\u6709\u6388\u6743<\/h2>\n\n\n\n<pre id=\"YOSsm\" class=\"wp-block-code\"><code>REVOKE ALL PRIVILEGES, GRANT OPTION FROM 'egon1'@'%';\nREVOKE ALL PRIVILEGES, GRANT OPTION FROM 'egon2'@'%';\nREVOKE ALL PRIVILEGES ON db1.t1 FROM 'egon3'@'%';\nREVOKE SELECT(id, name, age), UPDATE(age) ON db1.t1 FROM 'egon4'@'%';\n\nDROP USER 'egon1'@'%';\nDROP USER 'egon2'@'%';\nDROP USER 'egon3'@'%';\nDROP USER 'egon4'@'%';<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"r6KyN\">\u9a8c\u8bc1\u6b65\u9aa4<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u9a8c\u8bc1 <\/strong><code>egon1<\/code><strong>\uff1a<\/strong> \u8fdc\u7a0b\u767b\u5f55\u540e\uff0c\u5e94\u80fd\u5bf9\u6240\u6709\u5e93\u548c\u8868\u8fdb\u884c\u6240\u6709\u64cd\u4f5c\uff08\u9664\u4e86\u6388\u4e88\u6743\u9650\uff09\u3002<\/li>\n\n\n\n<li><strong>\u9a8c\u8bc1 <\/strong><code>egon2<\/code><strong>\uff1a<\/strong> \u8fdc\u7a0b\u767b\u5f55\u540e\uff0c\u5e94\u80fd\u5bf9 <code>db1<\/code> \u5e93\u4e0b\u6240\u6709\u8868\u8fdb\u884c\u6240\u6709\u64cd\u4f5c\u3002<\/li>\n\n\n\n<li><strong>\u9a8c\u8bc1 <\/strong><code>egon3<\/code><strong>\uff1a<\/strong> \u8fdc\u7a0b\u767b\u5f55\u540e\uff0c\u53ea\u80fd\u770b\u5230 <code>db1<\/code> \u5e93\u4e0b\u7684 <code>t1<\/code> \u8868\uff0c\u5e76\u4e14\u53ea\u80fd\u6267\u884c SELECT \u64cd\u4f5c\u3002<\/li>\n\n\n\n<li><strong>\u9a8c\u8bc1 <\/strong><code>egon4<\/code><strong>\uff1a<\/strong> \u8fdc\u7a0b\u767b\u5f55\u540e\uff0c\u53ea\u80fd\u5bf9 <code>t1<\/code> \u8868\u7684 <code>id<\/code> \u548c <code>name<\/code> \u5b57\u6bb5\u6267\u884c SELECT \u64cd\u4f5c\uff0c\u5bf9 <code>age<\/code> \u5b57\u6bb5\u6267\u884c UPDATE \u64cd\u4f5c\u3002<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>1. \u521b\u5efa\u5e93 db1 \u548c\u7528\u6237\u8868 t1 \u9996\u5148\uff0c\u521b\u5efa\u6570\u636e\u5e93 db1\uff0c\u5e76\u5728\u5176\u4e2d\u521b\u5efa\u8868 t1\uff0c\u7136\u540e\u63d2\u516510\u6761\u8bb0\u5f55\u3002 2 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13,8],"tags":[10],"class_list":["post-260","post","type-post","status-publish","format-standard","hentry","category-mysql_privilege","category-mysql","tag-mysql_lab"],"_links":{"self":[{"href":"https:\/\/zhaoyanqi.cn\/index.php?rest_route=\/wp\/v2\/posts\/260","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zhaoyanqi.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zhaoyanqi.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zhaoyanqi.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zhaoyanqi.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=260"}],"version-history":[{"count":2,"href":"https:\/\/zhaoyanqi.cn\/index.php?rest_route=\/wp\/v2\/posts\/260\/revisions"}],"predecessor-version":[{"id":265,"href":"https:\/\/zhaoyanqi.cn\/index.php?rest_route=\/wp\/v2\/posts\/260\/revisions\/265"}],"wp:attachment":[{"href":"https:\/\/zhaoyanqi.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=260"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zhaoyanqi.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=260"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zhaoyanqi.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=260"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}