{"id":175523,"date":"2024-11-08T06:35:18","date_gmt":"2024-11-07T22:35:18","guid":{"rendered":"https:\/\/server.hk\/cnblog\/175523\/"},"modified":"2024-11-08T06:35:19","modified_gmt":"2024-11-07T22:35:19","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8%e8%99%9b%e6%93%ac%e4%b8%bb%e6%a9%9f%e6%90%ad%e5%bb%ba%e6%95%b8%e6%93%9a%e5%ba%ab%ef%bc%9f-%e8%99%9b%e6%93%ac%e4%b8%bb%e6%a9%9f%e6%95%b8%e6%93%9a%e5%ba%ab","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/175523\/","title":{"rendered":"\u5982\u4f55\u4f7f\u7528\u865b\u64ec\u4e3b\u6a5f\u642d\u5efa\u6578\u64da\u5eab\uff1f (\u865b\u64ec\u4e3b\u6a5f\u6578\u64da\u5eab)"},"content":{"rendered":"<h1 id=\"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8%e8%99%9b%e6%93%ac%e4%b8%bb%e6%a9%9f%e6%90%ad%e5%bb%ba%e6%95%b8%e6%93%9a%e5%ba%ab%ef%bc%9f-%e8%99%9b%e6%93%ac%e4%b8%bb%e6%a9%9f%e6%95%b8%e6%93%9a%e5%ba%ab-BtFvPJqjzI\">\u5982\u4f55\u4f7f\u7528\u865b\u64ec\u4e3b\u6a5f\u642d\u5efa\u6578\u64da\u5eab\uff1f (\u865b\u64ec\u4e3b\u6a5f\u6578\u64da\u5eab)<\/h1>\n<p>\u5728\u7576\u4eca\u6578\u5b57\u5316\u7684\u6642\u4ee3\uff0c\u6578\u64da\u5eab\u7684\u4f7f\u7528\u8b8a\u5f97\u8d8a\u4f86\u8d8a\u666e\u904d\u3002\u7121\u8ad6\u662f\u500b\u4eba\u7db2\u7ad9\u9084\u662f\u4f01\u696d\u61c9\u7528\uff0c\u6578\u64da\u5eab\u90fd\u662f\u5b58\u5132\u548c\u7ba1\u7406\u6578\u64da\u7684\u6838\u5fc3\u7d44\u4ef6\u3002\u865b\u64ec\u4e3b\u6a5f\uff08VPS\uff09\u63d0\u4f9b\u4e86\u4e00\u500b\u9748\u6d3b\u4e14\u7d93\u6fdf\u7684\u89e3\u6c7a\u65b9\u6848\u4f86\u642d\u5efa\u548c\u7ba1\u7406\u6578\u64da\u5eab\u3002\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u5728\u865b\u64ec\u4e3b\u6a5f\u4e0a\u642d\u5efa\u6578\u64da\u5eab\uff0c\u4e26\u63d0\u4f9b\u4e00\u4e9b\u5be6\u7528\u7684\u6b65\u9a5f\u548c\u793a\u4f8b\u3002<\/p>\n<h2 id=\"%e9%81%b8%e6%93%87%e5%90%88%e9%81%a9%e7%9a%84%e8%99%9b%e6%93%ac%e4%b8%bb%e6%a9%9f-BtFvPJqjzI\">\u9078\u64c7\u5408\u9069\u7684\u865b\u64ec\u4e3b\u6a5f<\/h2>\n<p>\u5728\u958b\u59cb\u642d\u5efa\u6578\u64da\u5eab\u4e4b\u524d\uff0c\u9996\u5148\u9700\u8981\u9078\u64c7\u4e00\u500b\u5408\u9069\u7684\u865b\u64ec\u4e3b\u6a5f\u670d\u52d9\u3002\u9078\u64c7\u6642\u61c9\u8003\u616e\u4ee5\u4e0b\u5e7e\u500b\u56e0\u7d20\uff1a<\/p>\n<ul>\n<li><strong>\u6027\u80fd\uff1a<\/strong>\u78ba\u4fdd\u865b\u64ec\u4e3b\u6a5f\u63d0\u4f9b\u8db3\u5920\u7684CPU\u3001\u5167\u5b58\u548c\u5b58\u5132\u7a7a\u9593\uff0c\u4ee5\u652f\u6301\u6578\u64da\u5eab\u7684\u904b\u884c\u3002<\/li>\n<li><strong>\u64cd\u4f5c\u7cfb\u7d71\uff1a<\/strong>\u6839\u64da\u81ea\u5df1\u7684\u9700\u6c42\u9078\u64c7Linux\u6216Windows\u7cfb\u7d71\uff0c\u56e0\u70ba\u4e0d\u540c\u7684\u6578\u64da\u5eab\u7ba1\u7406\u7cfb\u7d71\uff08DBMS\uff09\u5c0d\u64cd\u4f5c\u7cfb\u7d71\u7684\u652f\u6301\u6709\u6240\u4e0d\u540c\u3002<\/li>\n<li><strong>\u5b89\u5168\u6027\uff1a<\/strong>\u9078\u64c7\u63d0\u4f9b\u826f\u597d\u5b89\u5168\u63aa\u65bd\u7684\u865b\u64ec\u4e3b\u6a5f\uff0c\u4ee5\u4fdd\u8b77\u6578\u64da\u7684\u5b89\u5168\u6027\u3002<\/li>\n<li><strong>\u6280\u8853\u652f\u6301\uff1a<\/strong>\u78ba\u4fdd\u865b\u64ec\u4e3b\u6a5f\u63d0\u4f9b24\/7\u7684\u6280\u8853\u652f\u6301\uff0c\u4ee5\u4fbf\u5728\u9047\u5230\u554f\u984c\u6642\u80fd\u5920\u53ca\u6642\u7372\u5f97\u5e6b\u52a9\u3002<\/li>\n<\/ul>\n<h2 id=\"%e5%ae%89%e8%a3%9d%e6%95%b8%e6%93%9a%e5%ba%ab%e7%ae%a1%e7%90%86%e7%b3%bb%e7%b5%b1-BtFvPJqjzI\">\u5b89\u88dd\u6578\u64da\u5eab\u7ba1\u7406\u7cfb\u7d71<\/h2>\n<p>\u9078\u64c7\u597d\u865b\u64ec\u4e3b\u6a5f\u5f8c\uff0c\u63a5\u4e0b\u4f86\u9700\u8981\u5b89\u88dd\u6578\u64da\u5eab\u7ba1\u7406\u7cfb\u7d71\u3002\u4ee5\u4e0b\u662f\u5b89\u88ddMySQL\u6578\u64da\u5eab\u7684\u6b65\u9a5f\uff1a<\/p>\n<h3 id=\"1-%e7%99%bb%e9%8c%84%e8%99%9b%e6%93%ac%e4%b8%bb%e6%a9%9f-BtFvPJqjzI\">1. \u767b\u9304\u865b\u64ec\u4e3b\u6a5f<\/h3>\n<pre><code>ssh username@your_vps_ip<\/code><\/pre>\n<p>\u4f7f\u7528SSH\u767b\u9304\u5230\u60a8\u7684\u865b\u64ec\u4e3b\u6a5f\uff0c\u66ff\u63db<code>username<\/code>\u548c<code>your_vps_ip<\/code>\u70ba\u60a8\u7684\u7528\u6236\u540d\u548c\u865b\u64ec\u4e3b\u6a5f\u7684IP\u5730\u5740\u3002<\/p>\n<h3 id=\"2-%e6%9b%b4%e6%96%b0%e7%b3%bb%e7%b5%b1-BtFvPJqjzI\">2. \u66f4\u65b0\u7cfb\u7d71<\/h3>\n<pre><code>sudo apt update &amp;&amp; sudo apt upgrade<\/code><\/pre>\n<p>\u5728\u5b89\u88dd\u4efb\u4f55\u8edf\u4ef6\u4e4b\u524d\uff0c\u5efa\u8b70\u5148\u66f4\u65b0\u7cfb\u7d71\u4ee5\u78ba\u4fdd\u6240\u6709\u5305\u90fd\u662f\u6700\u65b0\u7684\u3002<\/p>\n<h3 id=\"3-%e5%ae%89%e8%a3%9dmysql-BtFvPJqjzI\">3. \u5b89\u88ddMySQL<\/h3>\n<pre><code>sudo apt install mysql-server<\/code><\/pre>\n<p>\u9019\u689d\u547d\u4ee4\u5c07\u5b89\u88ddMySQL\u6578\u64da\u5eab\u670d\u52d9\u5668\u3002\u5b89\u88dd\u904e\u7a0b\u4e2d\uff0c\u7cfb\u7d71\u53ef\u80fd\u6703\u8981\u6c42\u60a8\u8a2d\u7f6eroot\u7528\u6236\u7684\u5bc6\u78bc\u3002<\/p>\n<h3 id=\"4-%e9%85%8d%e7%bd%aemysql-BtFvPJqjzI\">4. \u914d\u7f6eMySQL<\/h3>\n<pre><code>sudo mysql_secure_installation<\/code><\/pre>\n<p>\u904b\u884c\u6b64\u547d\u4ee4\u4ee5\u9032\u884c\u5b89\u5168\u914d\u7f6e\uff0c\u60a8\u53ef\u4ee5\u8a2d\u7f6e\u5bc6\u78bc\u5f37\u5ea6\u3001\u522a\u9664\u533f\u540d\u7528\u6236\u3001\u7981\u6b62root\u9060\u7a0b\u767b\u9304\u7b49\u3002<\/p>\n<h2 id=\"%e5%89%b5%e5%bb%ba%e6%95%b8%e6%93%9a%e5%ba%ab%e5%92%8c%e7%94%a8%e6%88%b6-BtFvPJqjzI\">\u5275\u5efa\u6578\u64da\u5eab\u548c\u7528\u6236<\/h2>\n<p>\u5b89\u88dd\u5b8c\u6210\u5f8c\uff0c\u60a8\u53ef\u4ee5\u958b\u59cb\u5275\u5efa\u6578\u64da\u5eab\u548c\u7528\u6236\u3002\u4ee5\u4e0b\u662f\u5275\u5efa\u6578\u64da\u5eab\u548c\u7528\u6236\u7684\u6b65\u9a5f\uff1a<\/p>\n<h3 id=\"1-%e7%99%bb%e9%8c%84mysql-BtFvPJqjzI\">1. \u767b\u9304MySQL<\/h3>\n<pre><code>sudo mysql -u root -p<\/code><\/pre>\n<p>\u8f38\u5165\u60a8\u5728\u5b89\u88dd\u904e\u7a0b\u4e2d\u8a2d\u7f6e\u7684root\u5bc6\u78bc\u3002<\/p>\n<h3 id=\"2-%e5%89%b5%e5%bb%ba%e6%95%b8%e6%93%9a%e5%ba%ab-BtFvPJqjzI\">2. \u5275\u5efa\u6578\u64da\u5eab<\/h3>\n<pre><code>CREATE DATABASE my_database;<\/code><\/pre>\n<p>\u5c07<code>my_database<\/code>\u66ff\u63db\u70ba\u60a8\u5e0c\u671b\u5275\u5efa\u7684\u6578\u64da\u5eab\u540d\u7a31\u3002<\/p>\n<h3 id=\"3-%e5%89%b5%e5%bb%ba%e7%94%a8%e6%88%b6%e4%b8%a6%e6%8e%88%e6%ac%8a-BtFvPJqjzI\">3. \u5275\u5efa\u7528\u6236\u4e26\u6388\u6b0a<\/h3>\n<pre><code>CREATE USER 'my_user'@'localhost' IDENTIFIED BY 'my_password';<\/code><\/pre>\n<pre><code>GRANT ALL PRIVILEGES ON my_database.* TO 'my_user'@'localhost';<\/code><\/pre>\n<pre><code>FLUSH PRIVILEGES;<\/code><\/pre>\n<p>\u5c07<code>my_user<\/code>\u548c<code>my_password<\/code>\u66ff\u63db\u70ba\u60a8\u5e0c\u671b\u4f7f\u7528\u7684\u7528\u6236\u540d\u548c\u5bc6\u78bc\u3002<\/p>\n<h2 id=\"%e9%80%a3%e6%8e%a5%e6%95%b8%e6%93%9a%e5%ba%ab-BtFvPJqjzI\">\u9023\u63a5\u6578\u64da\u5eab<\/h2>\n<p>\u6578\u64da\u5eab\u5275\u5efa\u5b8c\u6210\u5f8c\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u5404\u7a2e\u7de8\u7a0b\u8a9e\u8a00\uff08\u5982PHP\u3001Python\u7b49\uff09\u4f86\u9023\u63a5\u548c\u64cd\u4f5c\u6578\u64da\u5eab\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528PHP\u9023\u63a5MySQL\u7684\u793a\u4f8b\uff1a<\/p>\n<pre><code>&lt;?php\n$servername = \"localhost\";\n$username = \"my_user\";\n$password = \"my_password\";\n$dbname = \"my_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(\"\u9023\u63a5\u5931\u6557: \" . $conn-&gt;connect_error);\n}\necho \"\u9023\u63a5\u6210\u529f\";\n?&gt;<\/code><\/pre>\n<h2 id=\"%e7%b8%bd%e7%b5%90-BtFvPJqjzI\">\u7e3d\u7d50<\/h2>\n<p>\u5728\u865b\u64ec\u4e3b\u6a5f\u4e0a\u642d\u5efa\u6578\u64da\u5eab\u662f\u4e00\u500b\u76f8\u5c0d\u7c21\u55ae\u7684\u904e\u7a0b\uff0c\u53ea\u9700\u9078\u64c7\u5408\u9069\u7684\u865b\u64ec\u4e3b\u6a5f\uff0c\u5b89\u88dd\u6240\u9700\u7684\u6578\u64da\u5eab\u7ba1\u7406\u7cfb\u7d71\uff0c\u4e26\u9032\u884c\u5fc5\u8981\u7684\u914d\u7f6e\u5373\u53ef\u3002\u7121\u8ad6\u662f\u7528\u65bc\u500b\u4eba\u9805\u76ee\u9084\u662f\u5546\u696d\u61c9\u7528\uff0c\u865b\u64ec\u4e3b\u6a5f\u90fd\u80fd\u63d0\u4f9b\u9748\u6d3b\u7684\u89e3\u6c7a\u65b9\u6848\u4f86\u6eff\u8db3\u60a8\u7684\u9700\u6c42\u3002\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u9ad8\u6548\u7684\u865b\u64ec\u4e3b\u6a5f\u670d\u52d9\uff0c\u8003\u616e\u4f7f\u7528<a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a>\uff0c\u4ee5\u4fbf\u66f4\u597d\u5730\u652f\u6301\u60a8\u7684\u6578\u64da\u5eab\u61c9\u7528\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b78\u7fd2\u5982\u4f55\u4f7f\u7528\u865b\u64ec\u4e3b\u6a5f\u642d\u5efa\u6578\u64da\u5eab\uff0c\u5f9e\u9078\u64c7\u4e3b\u6a5f\u5230\u914d\u7f6e\u6578\u64da\u5eab\uff0c\u7c21\u55ae\u6b65\u9a5f\u52a9\u4f60\u8f15\u9b06\u4e0a\u624b\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-175523","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/175523","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=175523"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/175523\/revisions"}],"predecessor-version":[{"id":175524,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/175523\/revisions\/175524"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=175523"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=175523"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=175523"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}