{"id":4636,"date":"2025-07-17T09:52:45","date_gmt":"2025-07-17T00:52:45","guid":{"rendered":"https:\/\/eternalsphere.net\/echoes\/?p=4636"},"modified":"2026-06-06T10:30:36","modified_gmt":"2026-06-06T01:30:36","slug":"wcv590siinp8vqs","status":"publish","type":"post","link":"https:\/\/eternalsphere.net\/echoes\/index.php\/2025\/07\/17\/wcv590siinp8vqs\/","title":{"rendered":"MySQL \u4e2d\u4e3a\u4f55\u5e94\u521b\u5efa root \u4ee5\u5916\u7684\u7528\u6237\u8d26\u6237\uff1f"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u5728\u65e5\u5e38\u7684\u6570\u636e\u5e93\u7ba1\u7406\u548c\u7f51\u7ad9\u90e8\u7f72\u8fc7\u7a0b\u4e2d\uff0c\u5f88\u591a\u521d\u5b66\u8005\u6216\u5c0f\u578b\u9879\u76ee\u5e38\u5e38\u76f4\u63a5\u4f7f\u7528 root \u7528\u6237\u8fde\u63a5 MySQL \u6570\u636e\u5e93\u3002\u7136\u800c\uff0c\u8fd9\u79cd\u505a\u6cd5\u5b58\u5728\u8f83\u5927\u7684\u5b89\u5168\u9690\u60a3\u548c\u7ba1\u7406\u96be\u9898\u3002\u672c\u6587\u5c06\u4ece\u5b89\u5168\u6027\u3001\u6743\u9650\u63a7\u5236\u3001\u5ba1\u8ba1\u8ffd\u8e2a\u7b49\u89d2\u5ea6\u51fa\u53d1\uff0c\u4ecb\u7ecd\u4e3a\u4ec0\u4e48\u5e94\u5728 MySQL\uff08\u6216 MariaDB\uff09\u4e2d\u521b\u5efa root \u4ee5\u5916\u7684\u7528\u6237\uff0c\u5e76\u4e3a\u4e0d\u540c\u7528\u9014\u521b\u5efa\u4e13\u5c5e\u8d26\u6237\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\" \/>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e00\u3001root \u7528\u6237\u7684\u7279\u6027\u4e0e\u98ce\u9669<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">MySQL \u4e2d\u7684 root \u7528\u6237\u662f\u8d85\u7ea7\u7ba1\u7406\u5458\uff0c\u62e5\u6709\u6700\u9ad8\u7ea7\u522b\u7684\u6570\u636e\u5e93\u6743\u9650\uff0c\u5305\u62ec\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u521b\u5efa\u3001\u4fee\u6539\u3001\u5220\u9664\u4efb\u610f\u6570\u636e\u5e93\uff1b<\/li>\n\n\n\n<li>\u7ba1\u7406\u6240\u6709\u7528\u6237\u53ca\u5176\u6743\u9650\uff1b<\/li>\n\n\n\n<li>\u6267\u884c\u4efb\u610f SQL \u8bed\u53e5\uff08\u5305\u62ec DROP\u3001GRANT\u3001SHUTDOWN \u7b49\u9ad8\u98ce\u9669\u64cd\u4f5c\uff09\uff1b<\/li>\n\n\n\n<li>\u4fee\u6539\u6216\u7ed5\u8fc7\u6570\u636e\u5b89\u5168\u63a7\u5236\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e00\u65e6 root \u5bc6\u7801\u6cc4\u9732\uff0c\u653b\u51fb\u8005\u53ef\u4ee5\u5b8c\u5168\u63a7\u5236\u6570\u636e\u5e93\u7cfb\u7edf\uff0c\u9020\u6210\u4e25\u91cd\u540e\u679c\u3002\u5c06 root \u7528\u6237\u66b4\u9732\u7ed9\u5e94\u7528\u7a0b\u5e8f\u6216 Web \u524d\u7aef\uff0c\u66f4\u662f\u6781\u4e3a\u5371\u9669\u7684\u505a\u6cd5\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\" \/>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e8c\u3001\u6700\u5c0f\u6743\u9650\u539f\u5219\uff08Principle of Least Privilege\uff09<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u4fe1\u606f\u5b89\u5168\u9886\u57df\uff0c\u300c\u6700\u5c0f\u6743\u9650\u539f\u5219\u300d\u662f\u4e00\u9879\u57fa\u672c\u7406\u5ff5\u3002\u5373\u6bcf\u4e2a\u8d26\u53f7\u4ec5\u83b7\u5f97\u5b8c\u6210\u5176\u4efb\u52a1\u6240\u5fc5\u9700\u7684\u6700\u5c0f\u6743\u9650\uff0c\u907f\u514d\u6743\u9650\u8fc7\u9ad8\u5e26\u6765\u7684\u5b89\u5168\u5a01\u80c1\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728 MySQL \u4e2d\uff0c\u53ef\u4ee5\u4e3a\u4e0d\u540c\u5e94\u7528\u3001\u7a0b\u5e8f\u6216\u7528\u6237\u521b\u5efa\u72ec\u7acb\u7684\u8d26\u6237\uff0c\u5e76\u6839\u636e\u5176\u7528\u9014\u6388\u4e88\u7cbe\u786e\u7684\u6743\u9650\uff0c\u4f8b\u5982\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u53ea\u8bfb\u6743\u9650\uff08SELECT\uff09<\/li>\n\n\n\n<li>\u8bfb\u5199\u6743\u9650\uff08SELECT, INSERT, UPDATE, DELETE\uff09<\/li>\n\n\n\n<li>\u67b6\u6784\u7ba1\u7406\u6743\u9650\uff08CREATE, DROP, ALTER\uff09<\/li>\n\n\n\n<li>\u5907\u4efd\u6743\u9650\uff08LOCK TABLES, SELECT\uff09<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u901a\u8fc7\u6743\u9650\u7ec6\u5206\uff0c\u65e2\u6ee1\u8db3\u4e1a\u52a1\u9700\u8981\uff0c\u53c8\u63a7\u5236\u6f5c\u5728\u98ce\u9669\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\" \/>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e09\u3001\u4e3a\u4e0d\u540c\u7528\u9014\u521b\u5efa\u4e13\u7528\u8d26\u6237\u7684\u597d\u5904<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1. <strong>\u63d0\u5347\u7cfb\u7edf\u5b89\u5168\u6027<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u907f\u514d\u5c06\u9ad8\u6743\u9650\u8d26\u53f7\u66b4\u9732\u7ed9\u524d\u7aef\u5e94\u7528\u3002<\/li>\n\n\n\n<li>\u5373\u4f7f\u67d0\u4e2a\u5e94\u7528\u88ab\u653b\u51fb\uff0c\u4ec5\u4f1a\u6ce2\u53ca\u5bf9\u5e94\u7684\u6570\u636e\u5e93\u548c\u64cd\u4f5c\u6743\u9650\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">2. <strong>\u6743\u9650\u7ec6\u5316\u4e0e\u9694\u79bb<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u6bcf\u4e2a\u8d26\u53f7\u53ea\u80fd\u8bbf\u95ee\u5bf9\u5e94\u7684\u6570\u636e\u5e93\u3001\u8868\u6216\u64cd\u4f5c\u7c7b\u578b\uff0c\u9632\u6b62\u8d8a\u6743\u8bbf\u95ee\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">3. <strong>\u5ba1\u8ba1\u4e0e\u8ffd\u8e2a\u65b9\u4fbf<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u53ef\u4ee5\u6839\u636e\u8d26\u6237\u540d\u5224\u65ad\u662f\u8c01\u53d1\u8d77\u7684\u64cd\u4f5c\uff0c\u4fbf\u4e8e\u65e5\u5fd7\u5206\u6790\u4e0e\u95ee\u9898\u8ffd\u8e2a\u3002<\/li>\n\n\n\n<li>\u5f53\u67d0\u4e2a\u670d\u52a1\u6216\u8d26\u53f7\u4e0d\u518d\u4f7f\u7528\u65f6\uff0c\u76f4\u63a5\u5220\u9664\u8d26\u53f7\u5373\u53ef\uff0c\u4e0d\u5f71\u54cd\u5176\u4ed6\u90e8\u5206\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">4. <strong>\u9650\u5236\u6765\u6e90 IP<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>MySQL \u5141\u8bb8\u4e3a\u8d26\u53f7\u7ed1\u5b9a\u767b\u5f55\u4e3b\u673a\uff08\u5982 <code>'user'@'localhost'<\/code>\uff09\uff0c\u7981\u6b62\u4ece\u5176\u4ed6 IP \u767b\u5f55\uff0c\u8fdb\u4e00\u6b65\u52a0\u56fa\u5b89\u5168\u3002<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\" \/>\n\n\n\n<h2 class=\"wp-block-heading\">\u56db\u3001\u5b9e\u9645\u5e94\u7528\u573a\u666f\u4e3e\u4f8b<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u8d26\u53f7\u7528\u9014<\/th><th>\u63a8\u8350\u6743\u9650<\/th><th>\u4e3b\u673a\u9650\u5236<\/th><\/tr><\/thead><tbody><tr><td>\u7f51\u7ad9\u540e\u7aef\u7a0b\u5e8f<\/td><td>SELECT, INSERT, UPDATE, DELETE<\/td><td><code>'user'@'localhost'<\/code><\/td><\/tr><tr><td>\u6570\u636e\u5206\u6790\u5de5\u5177<\/td><td>SELECT<\/td><td><code>'report'@'%'<\/code><\/td><\/tr><tr><td>\u81ea\u52a8\u5907\u4efd\u4efb\u52a1<\/td><td>SELECT, LOCK TABLES<\/td><td><code>'backup'@'127.0.0.1'<\/code><\/td><\/tr><tr><td>\u5f00\u53d1\u73af\u5883\u6d4b\u8bd5<\/td><td>\u6240\u6709\u6743\u9650\uff08\u975e root\uff09<\/td><td><code>'dev'@'%'<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u901a\u8fc7\u5408\u7406\u914d\u7f6e\uff0c\u4e0d\u540c\u89d2\u8272\u7684\u7528\u6237\u65e2\u53ef\u5b89\u5168\u8bbf\u95ee\u6570\u636e\u5e93\uff0c\u53c8\u4e0d\u4f1a\u76f8\u4e92\u5e72\u6270\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\" \/>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e94\u3001\u5982\u4f55\u521b\u5efa\u666e\u901a\u7528\u6237\u53ca\u6388\u6743<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u4ee5\u521b\u5efa\u4e00\u4e2a\u4ec5\u62e5\u6709 <code>test_db<\/code> \u6570\u636e\u5e93\u8bfb\u5199\u6743\u9650\u7684\u7528\u6237\u4e3a\u4f8b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>CREATE USER 'appuser'@'localhost' IDENTIFIED BY 'secure_password';<br>GRANT SELECT, INSERT, UPDATE, DELETE ON test_db.* TO 'appuser'@'localhost';<br>FLUSH PRIVILEGES;<br><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u9700\u64a4\u9500\u6388\u6743\u6216\u5220\u9664\u7528\u6237\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>REVOKE ALL PRIVILEGES ON test_db.* FROM 'appuser'@'localhost';<br>DROP USER 'appuser'@'localhost';<br><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e5f\u53ef\u4f7f\u7528\u56fe\u5f62\u754c\u9762\u7684 phpMyAdmin \u8fdb\u884c\u7528\u6237\u7ba1\u7406\uff0c\u901a\u8fc7\u300c\u7528\u6237\u5e10\u6237\u300d\u9875\u9762\u67e5\u770b\u3001\u6dfb\u52a0\u6216\u7f16\u8f91\u8d26\u53f7\u6743\u9650\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\" \/>\n\n\n\n<h2 class=\"wp-block-heading\">\u516d\u3001\u603b\u7ed3<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u6570\u636e\u5e93\u7cfb\u7edf\u4e2d\uff0c\u4ec5\u4f7f\u7528 root \u7528\u6237\u8fdb\u884c\u6240\u6709\u64cd\u4f5c\u662f\u6781\u4e0d\u63a8\u8350\u7684\u884c\u4e3a\u3002\u901a\u8fc7\u4e3a\u6bcf\u4e2a\u5e94\u7528\u3001\u5de5\u5177\u6216\u7528\u6237\u521b\u5efa\u72ec\u7acb\u8d26\u6237\uff0c\u5e76\u4e25\u683c\u9650\u5b9a\u6743\u9650\u548c\u6765\u6e90\uff0c\u4e0d\u4ec5\u53ef\u4ee5\u964d\u4f4e\u6f5c\u5728\u7684\u653b\u51fb\u98ce\u9669\uff0c\u4e5f\u65b9\u4fbf\u540e\u671f\u7684\u7ba1\u7406\u4e0e\u7ef4\u62a4\u3002\u5c24\u5176\u5728\u751f\u4ea7\u73af\u5883\u4e2d\uff0c\u8d26\u53f7\u6743\u9650\u7684\u5408\u7406\u5206\u914d\uff0c\u662f\u6570\u636e\u5e93\u5b89\u5168\u7b56\u7565\u7684\u6838\u5fc3\u73af\u8282\u4e4b\u4e00\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5efa\u7acb\u826f\u597d\u7684\u8d26\u6237\u7ba1\u7406\u4f53\u7cfb\uff0c\u4ece\u521b\u5efa\u7b2c\u4e00\u4e2a\u975e root \u7528\u6237\u5f00\u59cb\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u65e5\u5e38\u7684\u6570\u636e\u5e93\u7ba1\u7406\u548c\u7f51\u7ad9\u90e8\u7f72\u8fc7\u7a0b\u4e2d\uff0c\u5f88\u591a\u521d\u5b66\u8005\u6216\u5c0f\u578b\u9879\u76ee\u5e38\u5e38\u76f4\u63a5\u4f7f\u7528 root \u7528\u6237\u8fde\u63a5 MySQL \u6570\u636e\u5e93\u3002\u7136\u800c\uff0c\u8fd9\u79cd\u505a\u6cd5\u5b58\u5728\u8f83\u5927\u7684\u5b89\u5168\u9690\u60a3\u548c\u7ba1\u7406\u96be\u9898\u3002\u672c\u6587\u5c06\u4ece\u5b89\u5168\u6027\u3001\u6743\u9650\u63a7\u5236\u3001\u5ba1\u8ba1\u8ffd\u8e2a\u7b49\u89d2\u5ea6\u51fa\u53d1\uff0c\u4ecb\u7ecd\u4e3a\u4ec0\u4e48\u5e94\u5728 MySQL\uff08\u6216 MariaDB\uff09\u4e2d\u521b\u5efa root \u4ee5\u5916\u7684\u7528\u6237\uff0c\u5e76\u4e3a\u4e0d\u540c\u7528\u9014\u521b\u5efa\u4e13\u5c5e\u8d26\u6237\u3002 \u4e00\u3001root \u7528\u6237\u7684\u7279\u6027\u4e0e\u98ce\u9669 MySQL \u4e2d\u7684 root \u7528\u6237\u662f\u8d85\u7ea7\u7ba1\u7406\u5458\uff0c\u62e5\u6709\u6700\u9ad8\u7ea7\u522b\u7684\u6570\u636e\u5e93\u6743\u9650\uff0c\u5305\u62ec\uff1a \u4e00\u65e6 root \u5bc6\u7801\u6cc4\u9732\uff0c\u653b\u51fb\u8005\u53ef\u4ee5\u5b8c\u5168\u63a7\u5236\u6570\u636e\u5e93\u7cfb\u7edf\uff0c\u9020\u6210\u4e25\u91cd\u540e\u679c\u3002\u5c06 root \u7528\u6237\u66b4\u9732\u7ed9\u5e94\u7528\u7a0b\u5e8f\u6216 Web \u524d\u7aef\uff0c\u66f4\u662f\u6781\u4e3a\u5371\u9669\u7684\u505a\u6cd5\u3002 \u4e8c\u3001\u6700\u5c0f\u6743\u9650\u539f\u5219\uff08Principle of Least Privilege\uff09 \u5728\u4fe1\u606f\u5b89\u5168\u9886\u57df\uff0c\u300c\u6700\u5c0f\u6743\u9650\u539f\u5219\u300d\u662f\u4e00\u9879\u57fa\u672c\u7406\u5ff5\u3002\u5373\u6bcf\u4e2a\u8d26\u53f7\u4ec5\u83b7\u5f97\u5b8c\u6210\u5176\u4efb\u52a1\u6240\u5fc5\u9700\u7684\u6700\u5c0f\u6743\u9650\uff0c\u907f\u514d\u6743\u9650\u8fc7\u9ad8\u5e26\u6765\u7684\u5b89\u5168\u5a01\u80c1\u3002 \u5728 MySQL \u4e2d\uff0c\u53ef\u4ee5\u4e3a\u4e0d\u540c\u5e94\u7528\u3001\u7a0b\u5e8f\u6216\u7528\u6237\u521b\u5efa\u72ec\u7acb\u7684\u8d26\u6237\uff0c\u5e76\u6839\u636e\u5176\u7528\u9014\u6388\u4e88\u7cbe\u786e\u7684\u6743\u9650\uff0c\u4f8b\u5982\uff1a \u901a\u8fc7\u6743\u9650\u7ec6\u5206\uff0c\u65e2\u6ee1\u8db3\u4e1a\u52a1\u9700\u8981\uff0c\u53c8\u63a7\u5236\u6f5c\u5728\u98ce\u9669\u3002 \u4e09\u3001\u4e3a\u4e0d\u540c\u7528\u9014\u521b\u5efa\u4e13\u7528\u8d26\u6237\u7684\u597d\u5904 1. \u63d0\u5347\u7cfb\u7edf\u5b89\u5168\u6027 2. \u6743\u9650\u7ec6\u5316\u4e0e\u9694\u79bb 3. \u5ba1\u8ba1\u4e0e\u8ffd\u8e2a\u65b9\u4fbf 4. \u9650\u5236\u6765\u6e90 IP \u56db\u3001\u5b9e\u9645\u5e94\u7528\u573a\u666f\u4e3e\u4f8b \u8d26\u53f7\u7528\u9014 \u63a8\u8350\u6743\u9650 \u4e3b\u673a\u9650\u5236 \u7f51\u7ad9\u540e\u7aef\u7a0b\u5e8f SELECT, INSERT, UPDATE, DELETE &hellip;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[57],"tags":[],"class_list":["post-4636","post","type-post","status-publish","format-standard","hentry","category-y8behyrmw-2lc"],"_links":{"self":[{"href":"https:\/\/eternalsphere.net\/echoes\/index.php\/wp-json\/wp\/v2\/posts\/4636","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/eternalsphere.net\/echoes\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/eternalsphere.net\/echoes\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/eternalsphere.net\/echoes\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/eternalsphere.net\/echoes\/index.php\/wp-json\/wp\/v2\/comments?post=4636"}],"version-history":[{"count":1,"href":"https:\/\/eternalsphere.net\/echoes\/index.php\/wp-json\/wp\/v2\/posts\/4636\/revisions"}],"predecessor-version":[{"id":4637,"href":"https:\/\/eternalsphere.net\/echoes\/index.php\/wp-json\/wp\/v2\/posts\/4636\/revisions\/4637"}],"wp:attachment":[{"href":"https:\/\/eternalsphere.net\/echoes\/index.php\/wp-json\/wp\/v2\/media?parent=4636"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/eternalsphere.net\/echoes\/index.php\/wp-json\/wp\/v2\/categories?post=4636"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/eternalsphere.net\/echoes\/index.php\/wp-json\/wp\/v2\/tags?post=4636"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}