{"id":166403,"date":"2024-11-05T16:12:09","date_gmt":"2024-11-05T08:12:09","guid":{"rendered":"https:\/\/server.hk\/cnblog\/166403\/"},"modified":"2024-11-05T16:12:10","modified_gmt":"2024-11-05T08:12:10","slug":"%e5%bf%ab%e9%80%9f%e6%b8%85%e7%a9%ba%e7%b6%b2%e7%ab%99%e6%95%b8%e6%93%9a%e5%ba%ab%e8%a1%a8%ef%bc%9a%e6%95%99%e4%bd%a0%e5%b9%be%e6%8b%9b-%e6%80%8e%e9%ba%bc%e6%b8%85%e7%a9%ba%e7%b6%b2%e7%ab%99%e6%95%b8","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/166403\/","title":{"rendered":"\u5feb\u901f\u6e05\u7a7a\u7db2\u7ad9\u6578\u64da\u5eab\u8868\uff1a\u6559\u4f60\u5e7e\u62db (\u600e\u9ebc\u6e05\u7a7a\u7db2\u7ad9\u6578\u64da\u5eab\u8868)"},"content":{"rendered":"<h1 id=\"%e5%bf%ab%e9%80%9f%e6%b8%85%e7%a9%ba%e7%b6%b2%e7%ab%99%e6%95%b8%e6%93%9a%e5%ba%ab%e8%a1%a8%ef%bc%9a%e6%95%99%e4%bd%a0%e5%b9%be%e6%8b%9b-cWYEqTyTYJ\">\u5feb\u901f\u6e05\u7a7a\u7db2\u7ad9\u6578\u64da\u5eab\u8868\uff1a\u6559\u4f60\u5e7e\u62db<\/h1>\n<p>\u5728\u7db2\u7ad9\u7ba1\u7406\u4e2d\uff0c\u6578\u64da\u5eab\u7684\u7dad\u8b77\u662f\u4e00\u9805\u91cd\u8981\u7684\u4efb\u52d9\u3002\u96a8\u8457\u6642\u9593\u7684\u63a8\u79fb\uff0c\u6578\u64da\u5eab\u4e2d\u53ef\u80fd\u6703\u7a4d\u7d2f\u5927\u91cf\u7684\u7121\u7528\u6578\u64da\uff0c\u9019\u4e0d\u50c5\u6703\u5f71\u97ff\u7db2\u7ad9\u7684\u6027\u80fd\uff0c\u9084\u53ef\u80fd\u5c0e\u81f4\u6578\u64da\u5eab\u7684\u7ba1\u7406\u8b8a\u5f97\u66f4\u52a0\u56f0\u96e3\u3002\u56e0\u6b64\uff0c\u5b9a\u671f\u6e05\u7a7a\u4e0d\u5fc5\u8981\u7684\u6578\u64da\u5eab\u8868\u662f\u975e\u5e38\u5fc5\u8981\u7684\u3002\u672c\u6587\u5c07\u4ecb\u7d39\u5e7e\u7a2e\u5feb\u901f\u6e05\u7a7a\u7db2\u7ad9\u6578\u64da\u5eab\u8868\u7684\u65b9\u6cd5\uff0c\u5e6b\u52a9\u4f60\u6709\u6548\u5730\u7ba1\u7406\u6578\u64da\u5eab\u3002<\/p>\n<h2 id=\"%e7%82%ba%e4%bb%80%e9%ba%bc%e9%9c%80%e8%a6%81%e6%b8%85%e7%a9%ba%e6%95%b8%e6%93%9a%e5%ba%ab%e8%a1%a8%ef%bc%9f-cWYEqTyTYJ\">\u70ba\u4ec0\u9ebc\u9700\u8981\u6e05\u7a7a\u6578\u64da\u5eab\u8868\uff1f<\/h2>\n<p>\u6e05\u7a7a\u6578\u64da\u5eab\u8868\u7684\u539f\u56e0\u6709\u5f88\u591a\uff0c\u4e3b\u8981\u5305\u62ec\uff1a<\/p>\n<ul>\n<li><strong>\u63d0\u5347\u6027\u80fd\uff1a<\/strong>\u96a8\u8457\u6578\u64da\u7684\u589e\u9577\uff0c\u6578\u64da\u5eab\u7684\u67e5\u8a62\u901f\u5ea6\u53ef\u80fd\u6703\u8b8a\u6162\u3002\u6e05\u7a7a\u4e0d\u5fc5\u8981\u7684\u6578\u64da\u53ef\u4ee5\u63d0\u9ad8\u67e5\u8a62\u6548\u7387\u3002<\/li>\n<li><strong>\u91cb\u653e\u7a7a\u9593\uff1a<\/strong>\u6578\u64da\u5eab\u7684\u5b58\u5132\u7a7a\u9593\u662f\u6709\u9650\u7684\uff0c\u5b9a\u671f\u6e05\u7406\u53ef\u4ee5\u91cb\u653e\u7a7a\u9593\uff0c\u907f\u514d\u8d85\u51fa\u914d\u984d\u3002<\/li>\n<li><strong>\u6578\u64da\u7ba1\u7406\uff1a<\/strong>\u6e05\u7a7a\u904e\u6642\u6216\u7121\u7528\u7684\u6578\u64da\u53ef\u4ee5\u4f7f\u6578\u64da\u5eab\u66f4\u52a0\u6574\u6f54\uff0c\u4fbf\u65bc\u7ba1\u7406\u548c\u7dad\u8b77\u3002<\/li>\n<\/ul>\n<h2 id=\"%e6%b8%85%e7%a9%ba%e6%95%b8%e6%93%9a%e5%ba%ab%e8%a1%a8%e7%9a%84%e6%96%b9%e6%b3%95-cWYEqTyTYJ\">\u6e05\u7a7a\u6578\u64da\u5eab\u8868\u7684\u65b9\u6cd5<\/h2>\n<h3 id=\"1-%e4%bd%bf%e7%94%a8-sql-%e8%aa%9e%e5%8f%a5-cWYEqTyTYJ\">1. \u4f7f\u7528 SQL \u8a9e\u53e5<\/h3>\n<p>\u6700\u76f4\u63a5\u7684\u65b9\u6cd5\u662f\u4f7f\u7528 SQL \u8a9e\u53e5\u4f86\u6e05\u7a7a\u6578\u64da\u5eab\u8868\u3002\u4ee5\u4e0b\u662f\u6e05\u7a7a\u8868\u7684\u57fa\u672c\u8a9e\u6cd5\uff1a<\/p>\n<pre><code>TRUNCATE TABLE \u8868\u540d;<\/code><\/pre>\n<p>\u4f8b\u5982\uff0c\u5982\u679c\u4f60\u60f3\u6e05\u7a7a\u540d\u70ba <code>users<\/code> \u7684\u8868\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre><code>TRUNCATE TABLE users;<\/code><\/pre>\n<p>\u9019\u500b\u547d\u4ee4\u6703\u522a\u9664\u8868\u4e2d\u7684\u6240\u6709\u8a18\u9304\uff0c\u4f46\u4e0d\u6703\u522a\u9664\u8868\u672c\u8eab\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u4f7f\u7528 <code>TRUNCATE<\/code> \u547d\u4ee4\u7121\u6cd5\u6062\u5fa9\u88ab\u522a\u9664\u7684\u6578\u64da\uff0c\u56e0\u6b64\u5728\u57f7\u884c\u4e4b\u524d\u8acb\u78ba\u4fdd\u5df2\u7d93\u5099\u4efd\u4e86\u91cd\u8981\u6578\u64da\u3002<\/p>\n<h3 id=\"2-%e4%bd%bf%e7%94%a8-delete-%e8%aa%9e%e5%8f%a5-cWYEqTyTYJ\">2. \u4f7f\u7528 DELETE \u8a9e\u53e5<\/h3>\n<p>\u5982\u679c\u4f60\u9700\u8981\u6839\u64da\u7279\u5b9a\u689d\u4ef6\u522a\u9664\u6578\u64da\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>DELETE<\/code> \u8a9e\u53e5\u3002\u9019\u7a2e\u65b9\u6cd5\u5141\u8a31\u4f60\u9078\u64c7\u6027\u5730\u522a\u9664\u6578\u64da\u3002\u4f8b\u5982\uff1a<\/p>\n<pre><code>DELETE FROM \u8868\u540d WHERE \u689d\u4ef6;<\/code><\/pre>\n<p>\u5982\u679c\u4f60\u60f3\u522a\u9664 <code>users<\/code> \u8868\u4e2d\u6240\u6709\u5e74\u9f61\u5c0f\u65bc 18 \u7684\u7528\u6236\uff0c\u53ef\u4ee5\u9019\u6a23\u5beb\uff1a<\/p>\n<pre><code>DELETE FROM users WHERE age &lt; 18;<\/code><\/pre>\n<p>\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u4f7f\u7528 <code>DELETE<\/code> \u8a9e\u53e5\u6703\u9010\u884c\u522a\u9664\u6578\u64da\uff0c\u9019\u53ef\u80fd\u6703\u6bd4 <code>TRUNCATE<\/code> \u66f4\u8017\u6642\u3002<\/p>\n<h3 id=\"3-%e4%bd%bf%e7%94%a8%e6%95%b8%e6%93%9a%e5%ba%ab%e7%ae%a1%e7%90%86%e5%b7%a5%e5%85%b7-cWYEqTyTYJ\">3. \u4f7f\u7528\u6578\u64da\u5eab\u7ba1\u7406\u5de5\u5177<\/h3>\n<p>\u8a31\u591a\u6578\u64da\u5eab\u7ba1\u7406\u5de5\u5177\uff08\u5982 phpMyAdmin\u3001MySQL Workbench \u7b49\uff09\u63d0\u4f9b\u4e86\u5716\u5f62\u754c\u9762\u4f86\u7ba1\u7406\u6578\u64da\u5eab\u3002\u4f60\u53ef\u4ee5\u901a\u904e\u9019\u4e9b\u5de5\u5177\u8f15\u9b06\u5730\u6e05\u7a7a\u8868\uff1a<\/p>\n<ul>\n<li>\u5728\u5de5\u5177\u4e2d\u9078\u64c7\u8981\u6e05\u7a7a\u7684\u8868\u3002<\/li>\n<li>\u5c0b\u627e\u201c\u6e05\u7a7a\u201d\u6216\u201c\u522a\u9664\u6240\u6709\u8a18\u9304\u201d\u7684\u9078\u9805\u3002<\/li>\n<li>\u78ba\u8a8d\u64cd\u4f5c\uff0c\u5de5\u5177\u5c07\u81ea\u52d5\u57f7\u884c\u76f8\u61c9\u7684 SQL \u8a9e\u53e5\u3002<\/li>\n<\/ul>\n<h3 id=\"4-%e8%87%aa%e5%8b%95%e5%8c%96%e8%85%b3%e6%9c%ac-cWYEqTyTYJ\">4. \u81ea\u52d5\u5316\u8173\u672c<\/h3>\n<p>\u5982\u679c\u4f60\u9700\u8981\u5b9a\u671f\u6e05\u7a7a\u6578\u64da\u5eab\u8868\uff0c\u53ef\u4ee5\u8003\u616e\u7de8\u5beb\u81ea\u52d5\u5316\u8173\u672c\u3002\u4f7f\u7528 PHP\u3001Python \u6216\u5176\u4ed6\u7de8\u7a0b\u8a9e\u8a00\uff0c\u53ef\u4ee5\u5b9a\u671f\u57f7\u884c\u6e05\u7a7a\u64cd\u4f5c\u3002\u4f8b\u5982\uff0c\u4f7f\u7528 PHP \u7684\u7c21\u55ae\u793a\u4f8b\uff1a<\/p>\n<pre><code>&lt;?php\n$servername = \"localhost\";\n$username = \"username\";\n$password = \"password\";\n$dbname = \"database\";\n\n\/\/ \u5275\u5efa\u9023\u63a5\n$conn = new mysqli($servername, $username, $password, $dbname);\n\n\/\/ \u6aa2\u67e5\u9023\u63a5\nif ($conn-&gt;connect_error) {\n    die(\"Connection failed: \" . $conn-&gt;connect_error);\n}\n\n\/\/ \u6e05\u7a7a\u8868\n$sql = \"TRUNCATE TABLE users\";\nif ($conn-&gt;query($sql) === TRUE) {\n    echo \"Table cleared successfully\";\n} else {\n    echo \"Error clearing table: \" . $conn-&gt;error;\n}\n\n$conn-&gt;close();\n?&gt;<\/code><\/pre>\n<h2 id=\"%e7%b8%bd%e7%b5%90-cWYEqTyTYJ\">\u7e3d\u7d50<\/h2>\n<p>\u6e05\u7a7a\u7db2\u7ad9\u6578\u64da\u5eab\u8868\u662f\u4e00\u9805\u91cd\u8981\u7684\u7dad\u8b77\u5de5\u4f5c\uff0c\u53ef\u4ee5\u63d0\u5347\u7db2\u7ad9\u6027\u80fd\u3001\u91cb\u653e\u5b58\u5132\u7a7a\u9593\u4e26\u7c21\u5316\u6578\u64da\u7ba1\u7406\u3002\u7121\u8ad6\u662f\u4f7f\u7528 SQL \u8a9e\u53e5\u3001\u6578\u64da\u5eab\u7ba1\u7406\u5de5\u5177\u9084\u662f\u81ea\u52d5\u5316\u8173\u672c\uff0c\u9078\u64c7\u5408\u9069\u7684\u65b9\u6cd5\u53ef\u4ee5\u5e6b\u52a9\u4f60\u9ad8\u6548\u5730\u7ba1\u7406\u6578\u64da\u5eab\u3002\u5c0d\u65bc\u9700\u8981\u7a69\u5b9a\u548c\u9ad8\u6548\u904b\u884c\u7684\u7db2\u7ad9\uff0c\u9078\u64c7\u5408\u9069\u7684 <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u6216 <a href=\"https:\/\/server.hk\">\u9999\u6e2f\u4f3a\u670d\u5668<\/a> \u65b9\u6848\u4e5f\u662f\u81f3\u95dc\u91cd\u8981\u7684\uff0c\u9019\u6a23\u53ef\u4ee5\u78ba\u4fdd\u4f60\u7684\u6578\u64da\u5eab\u904b\u884c\u5728\u6700\u4f73\u74b0\u5883\u4e2d\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b78\u7fd2\u5feb\u901f\u6e05\u7a7a\u7db2\u7ad9\u6578\u64da\u5eab\u8868\u7684\u6280\u5de7\uff0c\u7c21\u55ae\u6b65\u9a5f\u6559\u4f60\u5982\u4f55\u6709\u6548\u7ba1\u7406\u6578\u64da\uff0c\u63d0\u5347\u7db2\u7ad9\u6027\u80fd\u3002<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-166403","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/166403","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=166403"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/166403\/revisions"}],"predecessor-version":[{"id":166404,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/166403\/revisions\/166404"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=166403"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=166403"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=166403"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}