{"id":179284,"date":"2024-11-09T00:32:30","date_gmt":"2024-11-08T16:32:30","guid":{"rendered":"https:\/\/server.hk\/cnblog\/179284\/"},"modified":"2024-11-09T00:32:31","modified_gmt":"2024-11-08T16:32:31","slug":"%e5%a6%82%e4%bd%95%e9%a9%97%e8%ad%89%e6%95%b8%e6%93%9a%e5%ba%ab%e9%80%a3%e6%8e%a5%e6%88%90%e5%8a%9f%ef%bc%9f-%e9%a9%97%e8%ad%89%e6%95%b8%e6%93%9a%e5%ba%ab%e6%98%af%e5%90%a6%e9%80%a3%e6%8e%a5%e6%88%90","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/179284\/","title":{"rendered":"\u5982\u4f55\u9a57\u8b49\u6578\u64da\u5eab\u9023\u63a5\u6210\u529f\uff1f (\u9a57\u8b49\u6578\u64da\u5eab\u662f\u5426\u9023\u63a5\u6210\u529f)"},"content":{"rendered":"<h1 id=\"%e5%a6%82%e4%bd%95%e9%a9%97%e8%ad%89%e6%95%b8%e6%93%9a%e5%ba%ab%e9%80%a3%e6%8e%a5%e6%88%90%e5%8a%9f%ef%bc%9f-JvdRWCvqPa\">\u5982\u4f55\u9a57\u8b49\u6578\u64da\u5eab\u9023\u63a5\u6210\u529f\uff1f<\/h1>\n<p>\u5728\u73fe\u4ee3\u61c9\u7528\u7a0b\u5f0f\u958b\u767c\u4e2d\uff0c\u6578\u64da\u5eab\u7684\u9023\u63a5\u662f\u81f3\u95dc\u91cd\u8981\u7684\u4e00\u74b0\u3002\u7121\u8ad6\u662f\u7db2\u7ad9\u3001\u79fb\u52d5\u61c9\u7528\u9084\u662f\u4f01\u696d\u7cfb\u7d71\uff0c\u6578\u64da\u5eab\u7684\u7a69\u5b9a\u6027\u548c\u53ef\u7528\u6027\u90fd\u76f4\u63a5\u5f71\u97ff\u5230\u6574\u9ad4\u6027\u80fd\u3002\u56e0\u6b64\uff0c\u9a57\u8b49\u6578\u64da\u5eab\u9023\u63a5\u662f\u5426\u6210\u529f\u662f\u958b\u767c\u904e\u7a0b\u4e2d\u7684\u4e00\u500b\u91cd\u8981\u6b65\u9a5f\u3002\u672c\u6587\u5c07\u63a2\u8a0e\u5982\u4f55\u6709\u6548\u5730\u9a57\u8b49\u6578\u64da\u5eab\u9023\u63a5\u6210\u529f\uff0c\u4e26\u63d0\u4f9b\u4e00\u4e9b\u5be6\u7528\u7684\u793a\u4f8b\u548c\u4ee3\u78bc\u7247\u6bb5\u3002<\/p>\n<h2 id=\"%e7%82%ba%e4%bb%80%e9%ba%bc%e9%9c%80%e8%a6%81%e9%a9%97%e8%ad%89%e6%95%b8%e6%93%9a%e5%ba%ab%e9%80%a3%e6%8e%a5%ef%bc%9f-JvdRWCvqPa\">\u70ba\u4ec0\u9ebc\u9700\u8981\u9a57\u8b49\u6578\u64da\u5eab\u9023\u63a5\uff1f<\/h2>\n<p>\u9a57\u8b49\u6578\u64da\u5eab\u9023\u63a5\u7684\u4e3b\u8981\u539f\u56e0\u5305\u62ec\uff1a<\/p>\n<ul>\n<li><strong>\u78ba\u4fdd\u61c9\u7528\u7a0b\u5f0f\u6b63\u5e38\u904b\u884c\uff1a<\/strong>\u5982\u679c\u6578\u64da\u5eab\u7121\u6cd5\u9023\u63a5\uff0c\u61c9\u7528\u7a0b\u5f0f\u5c07\u7121\u6cd5\u8a2a\u554f\u6240\u9700\u7684\u6578\u64da\uff0c\u5f9e\u800c\u5c0e\u81f4\u529f\u80fd\u5931\u6548\u3002<\/li>\n<li><strong>\u63d0\u9ad8\u7528\u6236\u9ad4\u9a57\uff1a<\/strong>\u53ca\u6642\u6aa2\u6e2c\u9023\u63a5\u554f\u984c\u53ef\u4ee5\u5e6b\u52a9\u958b\u767c\u8005\u5feb\u901f\u4fee\u5fa9\uff0c\u6e1b\u5c11\u7528\u6236\u9047\u5230\u7684\u554f\u984c\u3002<\/li>\n<li><strong>\u6545\u969c\u6392\u9664\uff1a<\/strong>\u901a\u904e\u9a57\u8b49\u9023\u63a5\uff0c\u53ef\u4ee5\u66f4\u5bb9\u6613\u5730\u8b58\u5225\u548c\u89e3\u6c7a\u6578\u64da\u5eab\u76f8\u95dc\u7684\u554f\u984c\u3002<\/li>\n<\/ul>\n<h2 id=\"%e5%a6%82%e4%bd%95%e9%a9%97%e8%ad%89%e6%95%b8%e6%93%9a%e5%ba%ab%e9%80%a3%e6%8e%a5%e6%88%90%e5%8a%9f-JvdRWCvqPa\">\u5982\u4f55\u9a57\u8b49\u6578\u64da\u5eab\u9023\u63a5\u6210\u529f<\/h2>\n<p>\u9a57\u8b49\u6578\u64da\u5eab\u9023\u63a5\u6210\u529f\u7684\u65b9\u6cd5\u53d6\u6c7a\u65bc\u6240\u4f7f\u7528\u7684\u6578\u64da\u5eab\u985e\u578b\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u898b\u7684\u6578\u64da\u5eab\u53ca\u5176\u9a57\u8b49\u9023\u63a5\u7684\u793a\u4f8b\uff1a<\/p>\n<h3 id=\"1-mysql-JvdRWCvqPa\">1. MySQL<\/h3>\n<p>\u5c0d\u65bc MySQL \u6578\u64da\u5eab\uff0c\u53ef\u4ee5\u4f7f\u7528 PHP \u4f86\u9a57\u8b49\u9023\u63a5\u3002\u4ee5\u4e0b\u662f\u793a\u4f8b\u4ee3\u78bc\uff1a<\/p>\n<pre><code>&lt;?php\n$servername = \"localhost\";\n$username = \"username\";\n$password = \"password\";\n$dbname = \"database_name\";\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(\"\u9023\u63a5\u5931\u6557: \" . $conn-&gt;connect_error);\n}\necho \"\u9023\u63a5\u6210\u529f\";\n$conn-&gt;close();\n?&gt;<\/code><\/pre>\n<h3 id=\"2-postgresql-JvdRWCvqPa\">2. PostgreSQL<\/h3>\n<p>\u5c0d\u65bc PostgreSQL \u6578\u64da\u5eab\uff0c\u53ef\u4ee5\u4f7f\u7528 Python \u7684 psycopg2 \u5eab\u4f86\u9a57\u8b49\u9023\u63a5\u3002\u4ee5\u4e0b\u662f\u793a\u4f8b\u4ee3\u78bc\uff1a<\/p>\n<pre><code>import psycopg2\n\ntry:\n    conn = psycopg2.connect(\n        dbname=\"database_name\",\n        user=\"username\",\n        password=\"password\",\n        host=\"localhost\"\n    )\n    print(\"\u9023\u63a5\u6210\u529f\")\nexcept Exception as e:\n    print(\"\u9023\u63a5\u5931\u6557:\", e)\nfinally:\n    if conn:\n        conn.close()\n<\/code><\/pre>\n<h3 id=\"3-sql-server-JvdRWCvqPa\">3. SQL Server<\/h3>\n<p>\u5c0d\u65bc SQL Server\uff0c\u53ef\u4ee5\u4f7f\u7528 C# \u4f86\u9a57\u8b49\u9023\u63a5\u3002\u4ee5\u4e0b\u662f\u793a\u4f8b\u4ee3\u78bc\uff1a<\/p>\n<pre><code>using System;\nusing System.Data.SqlClient;\n\nclass Program\n{\n    static void Main()\n    {\n        string connectionString = \"Server=localhost;Database=database_name;User Id=username;Password=password;\";\n        \n        using (SqlConnection conn = new SqlConnection(connectionString))\n        {\n            try\n            {\n                conn.Open();\n                Console.WriteLine(\"\u9023\u63a5\u6210\u529f\");\n            }\n            catch (Exception ex)\n            {\n                Console.WriteLine(\"\u9023\u63a5\u5931\u6557: \" + ex.Message);\n            }\n        }\n    }\n}\n<\/code><\/pre>\n<h2 id=\"%e5%b8%b8%e8%a6%8b%e7%9a%84%e9%80%a3%e6%8e%a5%e5%95%8f%e9%a1%8c%e5%8f%8a%e8%a7%a3%e6%b1%ba%e6%96%b9%e6%a1%88-JvdRWCvqPa\">\u5e38\u898b\u7684\u9023\u63a5\u554f\u984c\u53ca\u89e3\u6c7a\u65b9\u6848<\/h2>\n<p>\u5728\u9a57\u8b49\u6578\u64da\u5eab\u9023\u63a5\u6642\uff0c\u958b\u767c\u8005\u53ef\u80fd\u6703\u9047\u5230\u4e00\u4e9b\u5e38\u898b\u7684\u554f\u984c\uff1a<\/p>\n<ul>\n<li><strong>\u8a8d\u8b49\u5931\u6557\uff1a<\/strong>\u6aa2\u67e5\u7528\u6236\u540d\u548c\u5bc6\u78bc\u662f\u5426\u6b63\u78ba\u3002<\/li>\n<li><strong>\u4e3b\u6a5f\u7121\u6cd5\u8a2a\u554f\uff1a<\/strong>\u78ba\u4fdd\u6578\u64da\u5eab\u670d\u52d9\u5668\u6b63\u5728\u904b\u884c\uff0c\u4e26\u4e14\u9632\u706b\u7246\u8a2d\u7f6e\u5141\u8a31\u8a2a\u554f\u3002<\/li>\n<li><strong>\u6578\u64da\u5eab\u4e0d\u5b58\u5728\uff1a<\/strong>\u78ba\u8a8d\u6240\u9023\u63a5\u7684\u6578\u64da\u5eab\u540d\u7a31\u662f\u5426\u6b63\u78ba\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%b5%90%e8%ab%96-JvdRWCvqPa\">\u7d50\u8ad6<\/h2>\n<p>\u9a57\u8b49\u6578\u64da\u5eab\u9023\u63a5\u6210\u529f\u662f\u958b\u767c\u904e\u7a0b\u4e2d\u4e0d\u53ef\u6216\u7f3a\u7684\u4e00\u90e8\u5206\u3002\u901a\u904e\u4f7f\u7528\u9069\u7576\u7684\u7de8\u7a0b\u8a9e\u8a00\u548c\u5eab\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u8f15\u9b06\u5730\u6aa2\u67e5\u9023\u63a5\u72c0\u614b\uff0c\u5f9e\u800c\u78ba\u4fdd\u61c9\u7528\u7a0b\u5f0f\u7684\u7a69\u5b9a\u6027\u548c\u53ef\u9760\u6027\u3002\u7121\u8ad6\u60a8\u4f7f\u7528\u7684\u662f MySQL\u3001PostgreSQL \u9084\u662f SQL Server\uff0c\u4ee5\u4e0a\u793a\u4f8b\u90fd\u80fd\u5e6b\u52a9\u60a8\u5feb\u901f\u4e0a\u624b\u3002<\/p>\n<p>\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u9ad8\u6548\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u89e3\u6c7a\u65b9\u6848\uff0cServer.HK \u63d0\u4f9b\u591a\u7a2e\u9078\u64c7\uff0c\u6eff\u8db3\u4e0d\u540c\u9700\u6c42\u7684\u5ba2\u6236\u3002\u7121\u8ad6\u662f <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u9084\u662f\u5176\u4ed6\u670d\u52d9\uff0c\u6211\u5011\u90fd\u80fd\u70ba\u60a8\u63d0\u4f9b\u7a69\u5b9a\u7684\u652f\u6301\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b78\u7fd2\u5982\u4f55\u9a57\u8b49\u6578\u64da\u5eab\u9023\u63a5\u662f\u5426\u6210\u529f\uff0c\u5305\u62ec\u6aa2\u67e5\u9023\u63a5\u5b57\u7b26\u4e32\u3001\u57f7\u884c\u6e2c\u8a66\u67e5\u8a62\u53ca\u8655\u7406\u932f\u8aa4\u7684\u65b9\u6cd5\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-179284","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/179284","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=179284"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/179284\/revisions"}],"predecessor-version":[{"id":179285,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/179284\/revisions\/179285"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=179284"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=179284"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=179284"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}