{"id":190354,"date":"2024-11-12T11:53:18","date_gmt":"2024-11-12T03:53:18","guid":{"rendered":"https:\/\/server.hk\/cnblog\/190354\/"},"modified":"2024-11-12T11:53:19","modified_gmt":"2024-11-12T03:53:19","slug":"%e5%be%ae%e4%bf%a1%e5%b0%8f%e7%a8%8b%e5%ba%8f%e6%95%b8%e6%93%9a%e5%ba%ab%e6%90%ad%e5%bb%ba%e6%8c%87%e5%8d%97-%e5%be%ae%e4%bf%a1%e5%b0%8f%e7%a8%8b%e5%ba%8f%e6%80%8e%e9%ba%bc%e6%90%ad%e5%bb%ba%e6%95%b8","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/190354\/","title":{"rendered":"\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u6578\u64da\u5eab\u642d\u5efa\u6307\u5357 (\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u600e\u9ebc\u642d\u5efa\u6578\u64da\u5eab)"},"content":{"rendered":"<h1 id=\"%e5%be%ae%e4%bf%a1%e5%b0%8f%e7%a8%8b%e5%ba%8f%e6%95%b8%e6%93%9a%e5%ba%ab%e6%90%ad%e5%bb%ba%e6%8c%87%e5%8d%97-JTHVrBBotE\">\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u6578\u64da\u5eab\u642d\u5efa\u6307\u5357<\/h1>\n<p>\u96a8\u8457\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u7684\u666e\u53ca\uff0c\u8d8a\u4f86\u8d8a\u591a\u7684\u958b\u767c\u8005\u958b\u59cb\u95dc\u6ce8\u5982\u4f55\u70ba\u5176\u5c0f\u7a0b\u5e8f\u642d\u5efa\u4e00\u500b\u9ad8\u6548\u7684\u6578\u64da\u5eab\u3002\u6578\u64da\u5eab\u662f\u5c0f\u7a0b\u5e8f\u7684\u6838\u5fc3\u7d44\u4ef6\u4e4b\u4e00\uff0c\u8ca0\u8cac\u5b58\u5132\u548c\u7ba1\u7406\u7528\u6236\u6578\u64da\u3001\u696d\u52d9\u6578\u64da\u7b49\u3002\u672c\u6587\u5c07\u70ba\u60a8\u63d0\u4f9b\u4e00\u500b\u8a73\u7d30\u7684\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u6578\u64da\u5eab\u642d\u5efa\u6307\u5357\uff0c\u5e6b\u52a9\u60a8\u5feb\u901f\u4e0a\u624b\u3002<\/p>\n<h2 id=\"%e4%b8%80%e3%80%81%e9%81%b8%e6%93%87%e6%95%b8%e6%93%9a%e5%ba%ab%e9%a1%9e%e5%9e%8b-JTHVrBBotE\">\u4e00\u3001\u9078\u64c7\u6578\u64da\u5eab\u985e\u578b<\/h2>\n<p>\u5728\u642d\u5efa\u6578\u64da\u5eab\u4e4b\u524d\uff0c\u9996\u5148\u9700\u8981\u9078\u64c7\u5408\u9069\u7684\u6578\u64da\u5eab\u985e\u578b\u3002\u5e38\u898b\u7684\u6578\u64da\u5eab\u985e\u578b\u6709\u95dc\u4fc2\u578b\u6578\u64da\u5eab\u548c\u975e\u95dc\u4fc2\u578b\u6578\u64da\u5eab\u3002<\/p>\n<ul>\n<li><strong>\u95dc\u4fc2\u578b\u6578\u64da\u5eab\uff1a<\/strong>\u5982 MySQL\u3001PostgreSQL \u7b49\uff0c\u9069\u5408\u9700\u8981\u8907\u96dc\u67e5\u8a62\u548c\u4e8b\u52d9\u8655\u7406\u7684\u61c9\u7528\u3002<\/li>\n<li><strong>\u975e\u95dc\u4fc2\u578b\u6578\u64da\u5eab\uff1a<\/strong>\u5982 MongoDB\u3001Redis \u7b49\uff0c\u9069\u5408\u9700\u8981\u9ad8\u6027\u80fd\u548c\u9748\u6d3b\u6578\u64da\u7d50\u69cb\u7684\u61c9\u7528\u3002<\/li>\n<\/ul>\n<p>\u6839\u64da\u5c0f\u7a0b\u5e8f\u7684\u9700\u6c42\uff0c\u9078\u64c7\u5408\u9069\u7684\u6578\u64da\u5eab\u985e\u578b\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002\u5982\u679c\u60a8\u7684\u5c0f\u7a0b\u5e8f\u9700\u8981\u8655\u7406\u5927\u91cf\u7684\u7d50\u69cb\u5316\u6578\u64da\uff0c\u5efa\u8b70\u9078\u64c7\u95dc\u4fc2\u578b\u6578\u64da\u5eab\uff1b\u5982\u679c\u9700\u8981\u5feb\u901f\u8b80\u53d6\u548c\u5beb\u5165\u6578\u64da\uff0c\u5247\u53ef\u4ee5\u8003\u616e\u975e\u95dc\u4fc2\u578b\u6578\u64da\u5eab\u3002<\/p>\n<h2 id=\"%e4%ba%8c%e3%80%81%e6%90%ad%e5%bb%ba%e6%95%b8%e6%93%9a%e5%ba%ab-JTHVrBBotE\">\u4e8c\u3001\u642d\u5efa\u6578\u64da\u5eab<\/h2>\n<p>\u4ee5\u4e0b\u662f\u642d\u5efa\u6578\u64da\u5eab\u7684\u4e00\u822c\u6b65\u9a5f\uff0c\u4ee5 MySQL \u70ba\u4f8b\uff1a<\/p>\n<h3 id=\"1-%e5%ae%89%e8%a3%9d-mysql-JTHVrBBotE\">1. \u5b89\u88dd MySQL<\/h3>\n<pre><code>sudo apt-get update\nsudo apt-get install mysql-server\n<\/code><\/pre>\n<h3 id=\"2-%e9%85%8d%e7%bd%ae-mysql-JTHVrBBotE\">2. \u914d\u7f6e MySQL<\/h3>\n<p>\u5b89\u88dd\u5b8c\u6210\u5f8c\uff0c\u60a8\u9700\u8981\u9032\u884c\u4e00\u4e9b\u57fa\u672c\u914d\u7f6e\uff1a<\/p>\n<pre><code>sudo mysql_secure_installation\n<\/code><\/pre>\n<p>\u6839\u64da\u63d0\u793a\u8a2d\u7f6e root \u5bc6\u78bc\uff0c\u4e26\u9078\u64c7\u5176\u4ed6\u5b89\u5168\u9078\u9805\u3002<\/p>\n<h3 id=\"3-%e5%89%b5%e5%bb%ba%e6%95%b8%e6%93%9a%e5%ba%ab%e5%92%8c%e7%94%a8%e6%88%b6-JTHVrBBotE\">3. \u5275\u5efa\u6578\u64da\u5eab\u548c\u7528\u6236<\/h3>\n<pre><code>mysql -u root -p\nCREATE DATABASE wechat_app;\nCREATE USER 'wechat_user'@'localhost' IDENTIFIED BY 'password';\nGRANT ALL PRIVILEGES ON wechat_app.* TO 'wechat_user'@'localhost';\nFLUSH PRIVILEGES;\n<\/code><\/pre>\n<h2 id=\"%e4%b8%89%e3%80%81%e9%80%a3%e6%8e%a5%e6%95%b8%e6%93%9a%e5%ba%ab-JTHVrBBotE\">\u4e09\u3001\u9023\u63a5\u6578\u64da\u5eab<\/h2>\n<p>\u5728\u5c0f\u7a0b\u5e8f\u4e2d\uff0c\u60a8\u9700\u8981\u4f7f\u7528\u5f8c\u7aef\u670d\u52d9\u4f86\u9023\u63a5\u6578\u64da\u5eab\u3002\u9019\u88e1\u4ee5 Node.js \u70ba\u4f8b\uff0c\u4f7f\u7528 mysql \u6a21\u584a\u4f86\u9023\u63a5 MySQL \u6578\u64da\u5eab\uff1a<\/p>\n<pre><code>const mysql = require('mysql');\n\nconst connection = mysql.createConnection({\n    host: 'localhost',\n    user: 'wechat_user',\n    password: 'password',\n    database: 'wechat_app'\n});\n\nconnection.connect((err) =&gt; {\n    if (err) {\n        console.error('Error connecting: ' + err.stack);\n        return;\n    }\n    console.log('Connected as id ' + connection.threadId);\n});\n<\/code><\/pre>\n<h2 id=\"%e5%9b%9b%e3%80%81%e6%95%b8%e6%93%9a%e6%93%8d%e4%bd%9c-JTHVrBBotE\">\u56db\u3001\u6578\u64da\u64cd\u4f5c<\/h2>\n<p>\u9023\u63a5\u6210\u529f\u5f8c\uff0c\u60a8\u53ef\u4ee5\u9032\u884c\u6578\u64da\u7684\u589e\u522a\u6539\u67e5\u64cd\u4f5c\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u57fa\u672c\u7684\u64cd\u4f5c\u793a\u4f8b\uff1a<\/p>\n<h3 id=\"1-%e6%8f%92%e5%85%a5%e6%95%b8%e6%93%9a-JTHVrBBotE\">1. \u63d2\u5165\u6578\u64da<\/h3>\n<pre><code>const insertQuery = 'INSERT INTO users (name, age) VALUES (?, ?)';\nconnection.query(insertQuery, ['Alice', 25], (error, results) =&gt; {\n    if (error) throw error;\n    console.log('Inserted ID:', results.insertId);\n});\n<\/code><\/pre>\n<h3 id=\"2-%e6%9f%a5%e8%a9%a2%e6%95%b8%e6%93%9a-JTHVrBBotE\">2. \u67e5\u8a62\u6578\u64da<\/h3>\n<pre><code>const selectQuery = 'SELECT * FROM users';\nconnection.query(selectQuery, (error, results) =&gt; {\n    if (error) throw error;\n    console.log('User data:', results);\n});\n<\/code><\/pre>\n<h2 id=\"%e4%ba%94%e3%80%81%e6%b3%a8%e6%84%8f%e4%ba%8b%e9%a0%85-JTHVrBBotE\">\u4e94\u3001\u6ce8\u610f\u4e8b\u9805<\/h2>\n<p>\u5728\u642d\u5efa\u548c\u4f7f\u7528\u6578\u64da\u5eab\u6642\uff0c\u9700\u6ce8\u610f\u4ee5\u4e0b\u5e7e\u9ede\uff1a<\/p>\n<ul>\n<li>\u5b9a\u671f\u5099\u4efd\u6578\u64da\uff0c\u4ee5\u9632\u6578\u64da\u4e1f\u5931\u3002<\/li>\n<li>\u8a2d\u7f6e\u5408\u9069\u7684\u6b0a\u9650\uff0c\u78ba\u4fdd\u6578\u64da\u5b89\u5168\u3002<\/li>\n<li>\u512a\u5316\u67e5\u8a62\u6027\u80fd\uff0c\u907f\u514d\u4e0d\u5fc5\u8981\u7684\u6027\u80fd\u640d\u8017\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%b8%bd%e7%b5%90-JTHVrBBotE\">\u7e3d\u7d50<\/h2>\n<p>\u642d\u5efa\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u7684\u6578\u64da\u5eab\u662f\u4e00\u500b\u91cd\u8981\u7684\u6b65\u9a5f\uff0c\u9078\u64c7\u5408\u9069\u7684\u6578\u64da\u5eab\u985e\u578b\u3001\u6b63\u78ba\u914d\u7f6e\u548c\u64cd\u4f5c\u6578\u64da\u5eab\u90fd\u662f\u6210\u529f\u7684\u95dc\u9375\u3002\u5e0c\u671b\u672c\u6587\u80fd\u5e6b\u52a9\u60a8\u9806\u5229\u642d\u5efa\u81ea\u5df1\u7684\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u6578\u64da\u5eab\u3002\u5982\u679c\u60a8\u9700\u8981\u7a69\u5b9a\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u4f86\u652f\u6301\u60a8\u7684\u5c0f\u7a0b\u5e8f\u904b\u884c\uff0cServer.HK \u63d0\u4f9b\u591a\u7a2e <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u89e3\u6c7a\u65b9\u6848\uff0c\u6eff\u8db3\u60a8\u7684\u9700\u6c42\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e86\u89e3\u5982\u4f55\u642d\u5efa\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u6578\u64da\u5eab\uff0c\u5f9e\u9078\u64c7\u6578\u64da\u5eab\u5230\u5be6\u73fe\u6578\u64da\u4ea4\u4e92\uff0c\u63d0\u4f9b\u5168\u9762\u7684\u6b65\u9a5f\u548c\u5be6\u7528\u6280\u5de7\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-190354","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/190354","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=190354"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/190354\/revisions"}],"predecessor-version":[{"id":190355,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/190354\/revisions\/190355"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=190354"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=190354"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=190354"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}