{"id":171581,"date":"2024-11-07T03:56:19","date_gmt":"2024-11-06T19:56:19","guid":{"rendered":"https:\/\/server.hk\/cnblog\/171581\/"},"modified":"2024-11-07T03:56:20","modified_gmt":"2024-11-06T19:56:20","slug":"%e5%b7%a7%e7%94%a8mysql%e5%8a%a0%e5%af%86%e5%87%bd%e6%95%b8%e5%b0%8dweb%e7%b6%b2%e7%ab%99%e6%95%8f%e6%84%9f%e6%95%b8%e6%93%9a%e9%80%b2%e8%a1%8c%e4%bf%9d%e8%ad%b7","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/171581\/","title":{"rendered":"\u5de7\u7528MySQL\u52a0\u5bc6\u51fd\u6578\u5c0dWeb\u7db2\u7ad9\u654f\u611f\u6578\u64da\u9032\u884c\u4fdd\u8b77"},"content":{"rendered":"<h1 id=\"%e5%b7%a7%e7%94%a8mysql%e5%8a%a0%e5%af%86%e5%87%bd%e6%95%b8%e5%b0%8dweb%e7%b6%b2%e7%ab%99%e6%95%8f%e6%84%9f%e6%95%b8%e6%93%9a%e9%80%b2%e8%a1%8c%e4%bf%9d%e8%ad%b7-LEoaopROSk\">\u5de7\u7528MySQL\u52a0\u5bc6\u51fd\u6578\u5c0dWeb\u7db2\u7ad9\u654f\u611f\u6578\u64da\u9032\u884c\u4fdd\u8b77<\/h1>\n<p>\u5728\u7576\u4eca\u6578\u5b57\u5316\u7684\u6642\u4ee3\uff0c\u7db2\u7ad9\u5b89\u5168\u6027\u6210\u70ba\u4e86\u6bcf\u500b\u4f01\u696d\u548c\u958b\u767c\u8005\u5fc5\u9808\u91cd\u8996\u7684\u8ab2\u984c\u3002\u96a8\u8457\u6578\u64da\u6d29\u9732\u4e8b\u4ef6\u7684\u983b\u7e41\u767c\u751f\uff0c\u5982\u4f55\u6709\u6548\u5730\u4fdd\u8b77\u654f\u611f\u6578\u64da\uff0c\u7279\u5225\u662f\u5728Web\u61c9\u7528\u4e2d\uff0c\u6210\u70ba\u4e86\u91cd\u8981\u7684\u6311\u6230\u4e4b\u4e00\u3002MySQL\u4f5c\u70ba\u4e00\u500b\u6d41\u884c\u7684\u6578\u64da\u5eab\u7ba1\u7406\u7cfb\u7d71\uff0c\u63d0\u4f9b\u4e86\u591a\u7a2e\u52a0\u5bc6\u51fd\u6578\uff0c\u5e6b\u52a9\u958b\u767c\u8005\u5728\u5b58\u5132\u548c\u8655\u7406\u654f\u611f\u6578\u64da\u6642\u589e\u5f37\u5b89\u5168\u6027\u3002<\/p>\n<h2 id=\"%e7%82%ba%e4%bb%80%e9%ba%bc%e9%9c%80%e8%a6%81%e5%8a%a0%e5%af%86%e6%95%8f%e6%84%9f%e6%95%b8%e6%93%9a-LEoaopROSk\">\u70ba\u4ec0\u9ebc\u9700\u8981\u52a0\u5bc6\u654f\u611f\u6578\u64da<\/h2>\n<p>\u654f\u611f\u6578\u64da\u5305\u62ec\u7528\u6236\u7684\u500b\u4eba\u4fe1\u606f\u3001\u5bc6\u78bc\u3001\u4fe1\u7528\u5361\u865f\u78bc\u7b49\uff0c\u9019\u4e9b\u6578\u64da\u4e00\u65e6\u88ab\u672a\u7d93\u6388\u6b0a\u7684\u4eba\u58eb\u7372\u53d6\uff0c\u53ef\u80fd\u6703\u5c0e\u81f4\u56b4\u91cd\u7684\u5f8c\u679c\uff0c\u5982\u8eab\u4efd\u76dc\u7aca\u3001\u8ca1\u52d9\u640d\u5931\u7b49\u3002\u56e0\u6b64\uff0c\u5c0d\u9019\u4e9b\u6578\u64da\u9032\u884c\u52a0\u5bc6\u662f\u4fdd\u8b77\u7528\u6236\u96b1\u79c1\u548c\u4f01\u696d\u8072\u8b7d\u7684\u5fc5\u8981\u63aa\u65bd\u3002<\/p>\n<h2 id=\"mysql%e4%b8%ad%e7%9a%84%e5%8a%a0%e5%af%86%e5%87%bd%e6%95%b8-LEoaopROSk\">MySQL\u4e2d\u7684\u52a0\u5bc6\u51fd\u6578<\/h2>\n<p>MySQL\u63d0\u4f9b\u4e86\u591a\u7a2e\u52a0\u5bc6\u51fd\u6578\uff0c\u6700\u5e38\u7528\u7684\u5305\u62ec\uff1a<\/p>\n<ul>\n<li><code>AES_ENCRYPT()<\/code>\uff1a\u4f7f\u7528\u9ad8\u7d1a\u52a0\u5bc6\u6a19\u6e96\uff08AES\uff09\u5c0d\u6578\u64da\u9032\u884c\u52a0\u5bc6\u3002<\/li>\n<li><code>AES_DECRYPT()<\/code>\uff1a\u5c0d\u4f7f\u7528AES\u52a0\u5bc6\u7684\u6578\u64da\u9032\u884c\u89e3\u5bc6\u3002<\/li>\n<li><code>SHA1()<\/code>\uff1a\u751f\u6210\u6578\u64da\u7684SHA-1\u54c8\u5e0c\u503c\uff0c\u5e38\u7528\u65bc\u5b58\u5132\u5bc6\u78bc\u3002<\/li>\n<li><code>MD5()<\/code>\uff1a\u751f\u6210\u6578\u64da\u7684MD5\u54c8\u5e0c\u503c\uff0c\u96d6\u7136\u4e0d\u518d\u88ab\u8a8d\u70ba\u662f\u5b89\u5168\u7684\uff0c\u4f46\u4ecd\u7136\u5728\u67d0\u4e9b\u60c5\u6cc1\u4e0b\u4f7f\u7528\u3002<\/li>\n<\/ul>\n<h2 id=\"%e4%bd%bf%e7%94%a8aes%e5%8a%a0%e5%af%86%e5%87%bd%e6%95%b8%e7%9a%84%e7%a4%ba%e4%be%8b-LEoaopROSk\">\u4f7f\u7528AES\u52a0\u5bc6\u51fd\u6578\u7684\u793a\u4f8b<\/h2>\n<p>\u4ee5\u4e0b\u662f\u4e00\u500b\u4f7f\u7528AES\u52a0\u5bc6\u51fd\u6578\u7684\u7c21\u55ae\u793a\u4f8b\uff0c\u5c55\u793a\u5982\u4f55\u5728MySQL\u4e2d\u52a0\u5bc6\u548c\u89e3\u5bc6\u6578\u64da\uff1a<\/p>\n<pre><code>-- \u5275\u5efa\u4e00\u500b\u793a\u4f8b\u8868\nCREATE TABLE users (\n    id INT AUTO_INCREMENT PRIMARY KEY,\n    username VARCHAR(50) NOT NULL,\n    password VARBINARY(255) NOT NULL\n);\n\n-- \u63d2\u5165\u52a0\u5bc6\u7684\u5bc6\u78bc\nINSERT INTO users (username, password) VALUES ('user1', AES_ENCRYPT('mypassword', 'mysecretkey'));\n\n-- \u67e5\u8a62\u4e26\u89e3\u5bc6\u5bc6\u78bc\nSELECT username, AES_DECRYPT(password, 'mysecretkey') AS decrypted_password FROM users;\n<\/code><\/pre>\n<p>\u5728\u9019\u500b\u793a\u4f8b\u4e2d\uff0c\u6211\u5011\u9996\u5148\u5275\u5efa\u4e86\u4e00\u500b\u7528\u6236\u8868\uff0c\u7136\u5f8c\u4f7f\u7528<code>AES_ENCRYPT()<\/code>\u51fd\u6578\u5c07\u7528\u6236\u7684\u5bc6\u78bc\u52a0\u5bc6\u5f8c\u5b58\u5132\u5230\u6578\u64da\u5eab\u4e2d\u3002\u7576\u9700\u8981\u9a57\u8b49\u7528\u6236\u767b\u9304\u6642\uff0c\u53ef\u4ee5\u4f7f\u7528<code>AES_DECRYPT()<\/code>\u51fd\u6578\u4f86\u89e3\u5bc6\u5bc6\u78bc\u3002<\/p>\n<h2 id=\"%e6%b3%a8%e6%84%8f%e4%ba%8b%e9%a0%85-LEoaopROSk\">\u6ce8\u610f\u4e8b\u9805<\/h2>\n<p>\u5728\u4f7f\u7528MySQL\u7684\u52a0\u5bc6\u51fd\u6578\u6642\uff0c\u6709\u5e7e\u9ede\u9700\u8981\u7279\u5225\u6ce8\u610f\uff1a<\/p>\n<ul>\n<li>\u9078\u64c7\u5408\u9069\u7684\u52a0\u5bc6\u7b97\u6cd5\uff1aAES\u662f\u4e00\u7a2e\u5f37\u5927\u7684\u52a0\u5bc6\u7b97\u6cd5\uff0c\u4f46\u9700\u8981\u78ba\u4fdd\u5bc6\u9470\u7684\u5b89\u5168\u6027\u3002<\/li>\n<li>\u5b9a\u671f\u66f4\u65b0\u5bc6\u9470\uff1a\u70ba\u4e86\u589e\u5f37\u5b89\u5168\u6027\uff0c\u61c9\u5b9a\u671f\u66f4\u63db\u52a0\u5bc6\u5bc6\u9470\u3002<\/li>\n<li>\u907f\u514d\u4f7f\u7528\u904e\u6642\u7684\u54c8\u5e0c\u7b97\u6cd5\uff1a\u5982MD5\u548cSHA-1\uff0c\u9019\u4e9b\u7b97\u6cd5\u5df2\u88ab\u8b49\u660e\u4e0d\u5920\u5b89\u5168\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%b5%90%e8%ab%96-LEoaopROSk\">\u7d50\u8ad6<\/h2>\n<p>\u5728Web\u61c9\u7528\u4e2d\uff0c\u4fdd\u8b77\u654f\u611f\u6578\u64da\u662f\u81f3\u95dc\u91cd\u8981\u7684\u3002\u5229\u7528MySQL\u63d0\u4f9b\u7684\u52a0\u5bc6\u51fd\u6578\uff0c\u53ef\u4ee5\u6709\u6548\u5730\u52a0\u5f37\u6578\u64da\u7684\u5b89\u5168\u6027\uff0c\u964d\u4f4e\u6578\u64da\u6d29\u9732\u7684\u98a8\u96aa\u3002\u958b\u767c\u8005\u61c9\u8a72\u719f\u6089\u9019\u4e9b\u52a0\u5bc6\u6280\u8853\uff0c\u4e26\u5728\u8a2d\u8a08\u6578\u64da\u5eab\u6642\u5c07\u5176\u7d0d\u5165\u8003\u91cf\uff0c\u4ee5\u78ba\u4fdd\u7528\u6236\u6578\u64da\u7684\u5b89\u5168\u3002<\/p>\n<p>\u5982\u9700\u4e86\u89e3\u66f4\u591a\u6709\u95dc<code>VPS<\/code>\u3001<a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a>\u53ca\u5176\u4ed6\u76f8\u95dc\u670d\u52d9\u7684\u4fe1\u606f\uff0c\u8acb\u8a2a\u554f\u6211\u5011\u7684\u7db2\u7ad9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63a2\u7d22\u5982\u4f55\u5de7\u5999\u904b\u7528MySQL\u52a0\u5bc6\u51fd\u6578\uff0c\u4fdd\u8b77Web\u7db2\u7ad9\u4e2d\u7684\u654f\u611f\u6578\u64da\uff0c\u63d0\u5347\u5b89\u5168\u6027\u8207\u6578\u64da\u96b1\u79c1\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-171581","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/171581","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=171581"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/171581\/revisions"}],"predecessor-version":[{"id":171582,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/171581\/revisions\/171582"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=171581"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=171581"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=171581"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}