{"id":190678,"date":"2024-11-12T14:35:21","date_gmt":"2024-11-12T06:35:21","guid":{"rendered":"https:\/\/server.hk\/cnblog\/190678\/"},"modified":"2024-11-12T14:35:23","modified_gmt":"2024-11-12T06:35:23","slug":"%e7%84%a1%e9%9c%80%e5%ae%89%e8%a3%9d%e7%9a%84%e6%95%b8%e6%93%9a%e5%ba%ab%e6%93%8d%e4%bd%9c%e5%91%bd%e4%bb%a4-%e5%85%8d%e5%ae%89%e8%a3%9d%e6%95%b8%e6%93%9a%e5%ba%ab%e5%91%bd%e4%bb%a4","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/190678\/","title":{"rendered":"\u7121\u9700\u5b89\u88dd\u7684\u6578\u64da\u5eab\u64cd\u4f5c\u547d\u4ee4 (\u514d\u5b89\u88dd\u6578\u64da\u5eab\u547d\u4ee4)"},"content":{"rendered":"<h1 id=\"%e7%84%a1%e9%9c%80%e5%ae%89%e8%a3%9d%e7%9a%84%e6%95%b8%e6%93%9a%e5%ba%ab%e6%93%8d%e4%bd%9c%e5%91%bd%e4%bb%a4-%e5%85%8d%e5%ae%89%e8%a3%9d%e6%95%b8%e6%93%9a%e5%ba%ab%e5%91%bd%e4%bb%a4-LqPJbMGayK\">\u7121\u9700\u5b89\u88dd\u7684\u6578\u64da\u5eab\u64cd\u4f5c\u547d\u4ee4 (\u514d\u5b89\u88dd\u6578\u64da\u5eab\u547d\u4ee4)<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u6578\u64da\u9a45\u52d5\u6642\u4ee3\uff0c\u6578\u64da\u5eab\u7684\u7ba1\u7406\u548c\u64cd\u4f5c\u8b8a\u5f97\u8d8a\u4f86\u8d8a\u91cd\u8981\u3002\u5c0d\u65bc\u958b\u767c\u8005\u548c\u7cfb\u7d71\u7ba1\u7406\u54e1\u4f86\u8aaa\uff0c\u80fd\u5920\u5feb\u901f\u6709\u6548\u5730\u64cd\u4f5c\u6578\u64da\u5eab\u662f\u5fc5\u4e0d\u53ef\u5c11\u7684\u3002\u7136\u800c\uff0c\u50b3\u7d71\u7684\u6578\u64da\u5eab\u5b89\u88dd\u904e\u7a0b\u5f80\u5f80\u7e41\u7463\u4e14\u8017\u6642\u3002\u70ba\u4e86\u89e3\u6c7a\u9019\u4e00\u554f\u984c\uff0c\u7121\u9700\u5b89\u88dd\u7684\u6578\u64da\u5eab\u64cd\u4f5c\u547d\u4ee4\u61c9\u904b\u800c\u751f\uff0c\u9019\u4e9b\u547d\u4ee4\u5141\u8a31\u7528\u6236\u5728\u4e0d\u5b89\u88dd\u6578\u64da\u5eab\u7684\u60c5\u6cc1\u4e0b\u9032\u884c\u6578\u64da\u64cd\u4f5c\u3002<\/p>\n<h2 id=\"%e7%84%a1%e9%9c%80%e5%ae%89%e8%a3%9d%e7%9a%84%e6%95%b8%e6%93%9a%e5%ba%ab%e6%93%8d%e4%bd%9c%e5%91%bd%e4%bb%a4%e7%9a%84%e6%a6%82%e5%bf%b5-LqPJbMGayK\">\u7121\u9700\u5b89\u88dd\u7684\u6578\u64da\u5eab\u64cd\u4f5c\u547d\u4ee4\u7684\u6982\u5ff5<\/h2>\n<p>\u7121\u9700\u5b89\u88dd\u7684\u6578\u64da\u5eab\u64cd\u4f5c\u547d\u4ee4\u901a\u5e38\u662f\u6307\u90a3\u4e9b\u53ef\u4ee5\u76f4\u63a5\u5728\u547d\u4ee4\u884c\u754c\u9762\u4e2d\u57f7\u884c\u7684\u547d\u4ee4\uff0c\u9019\u4e9b\u547d\u4ee4\u4e0d\u9700\u8981\u7528\u6236\u5728\u672c\u5730\u74b0\u5883\u4e2d\u5b89\u88dd\u5b8c\u6574\u7684\u6578\u64da\u5eab\u7cfb\u7d71\u3002\u9019\u985e\u547d\u4ee4\u901a\u5e38\u4f9d\u8cf4\u65bc\u96f2\u7aef\u6578\u64da\u5eab\u670d\u52d9\u6216\u5bb9\u5668\u5316\u6280\u8853\uff0c\u4f7f\u7528\u8005\u53ef\u4ee5\u901a\u904e\u7c21\u55ae\u7684\u547d\u4ee4\u4f86\u8a2a\u554f\u548c\u64cd\u4f5c\u6578\u64da\u3002<\/p>\n<h2 id=\"%e5%b8%b8%e8%a6%8b%e7%9a%84%e7%84%a1%e9%9c%80%e5%ae%89%e8%a3%9d%e7%9a%84%e6%95%b8%e6%93%9a%e5%ba%ab%e6%93%8d%e4%bd%9c%e5%91%bd%e4%bb%a4-LqPJbMGayK\">\u5e38\u898b\u7684\u7121\u9700\u5b89\u88dd\u7684\u6578\u64da\u5eab\u64cd\u4f5c\u547d\u4ee4<\/h2>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u898b\u7684\u7121\u9700\u5b89\u88dd\u7684\u6578\u64da\u5eab\u64cd\u4f5c\u547d\u4ee4\u793a\u4f8b\uff0c\u9019\u4e9b\u547d\u4ee4\u53ef\u4ee5\u7528\u65bc\u4e0d\u540c\u7684\u6578\u64da\u5eab\u7cfb\u7d71\uff0c\u5982 MySQL\u3001PostgreSQL \u548c SQLite\u3002<\/p>\n<h3 id=\"1-%e4%bd%bf%e7%94%a8-docker-%e6%93%8d%e4%bd%9c-mysql-LqPJbMGayK\">1. \u4f7f\u7528 Docker \u64cd\u4f5c MySQL<\/h3>\n<pre><code>docker run --name mysql-container -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:latest<\/code><\/pre>\n<p>\u9019\u689d\u547d\u4ee4\u6703\u555f\u52d5\u4e00\u500b MySQL \u5bb9\u5668\uff0c\u4e26\u8a2d\u7f6e\u6839\u7528\u6236\u7684\u5bc6\u78bc\u3002\u7528\u6236\u53ef\u4ee5\u901a\u904e\u4ee5\u4e0b\u547d\u4ee4\u9032\u5165 MySQL \u547d\u4ee4\u884c\u754c\u9762\uff1a<\/p>\n<pre><code>docker exec -it mysql-container mysql -uroot -p<\/code><\/pre>\n<h3 id=\"2-%e4%bd%bf%e7%94%a8-docker-%e6%93%8d%e4%bd%9c-postgresql-LqPJbMGayK\">2. \u4f7f\u7528 Docker \u64cd\u4f5c PostgreSQL<\/h3>\n<pre><code>docker run --name postgres-container -e POSTGRES_PASSWORD=mysecretpassword -d postgres<\/code><\/pre>\n<p>\u9019\u689d\u547d\u4ee4\u6703\u555f\u52d5\u4e00\u500b PostgreSQL \u5bb9\u5668\uff0c\u4e26\u8a2d\u7f6e\u7528\u6236\u7684\u5bc6\u78bc\u3002\u7528\u6236\u53ef\u4ee5\u901a\u904e\u4ee5\u4e0b\u547d\u4ee4\u9032\u5165 PostgreSQL \u547d\u4ee4\u884c\u754c\u9762\uff1a<\/p>\n<pre><code>docker exec -it postgres-container psql -U postgres<\/code><\/pre>\n<h3 id=\"3-%e4%bd%bf%e7%94%a8-sqlite-LqPJbMGayK\">3. \u4f7f\u7528 SQLite<\/h3>\n<p>SQLite \u662f\u4e00\u500b\u8f15\u91cf\u7d1a\u7684\u6578\u64da\u5eab\uff0c\u7121\u9700\u5b89\u88dd\u5373\u53ef\u4f7f\u7528\u3002\u7528\u6236\u53ea\u9700\u5728\u547d\u4ee4\u884c\u4e2d\u904b\u884c\u4ee5\u4e0b\u547d\u4ee4\u5373\u53ef\u5275\u5efa\u4e00\u500b\u65b0\u7684 SQLite \u6578\u64da\u5eab\uff1a<\/p>\n<pre><code>sqlite3 mydatabase.db<\/code><\/pre>\n<p>\u9032\u5165 SQLite \u547d\u4ee4\u884c\u5f8c\uff0c\u7528\u6236\u53ef\u4ee5\u57f7\u884c SQL \u67e5\u8a62\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre><code>CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT);<\/code><\/pre>\n<h2 id=\"%e7%84%a1%e9%9c%80%e5%ae%89%e8%a3%9d%e7%9a%84%e6%95%b8%e6%93%9a%e5%ba%ab%e6%93%8d%e4%bd%9c%e5%91%bd%e4%bb%a4%e7%9a%84%e5%84%aa%e5%8b%a2-LqPJbMGayK\">\u7121\u9700\u5b89\u88dd\u7684\u6578\u64da\u5eab\u64cd\u4f5c\u547d\u4ee4\u7684\u512a\u52e2<\/h2>\n<ul>\n<li><strong>\u5feb\u901f\u90e8\u7f72\uff1a<\/strong>\u7528\u6236\u53ef\u4ee5\u5feb\u901f\u555f\u52d5\u6578\u64da\u5eab\u5be6\u4f8b\uff0c\u800c\u7121\u9700\u7e41\u7463\u7684\u5b89\u88dd\u904e\u7a0b\u3002<\/li>\n<li><strong>\u8cc7\u6e90\u7bc0\u7701\uff1a<\/strong>\u7121\u9700\u5728\u672c\u5730\u74b0\u5883\u4e2d\u5b89\u88dd\u548c\u914d\u7f6e\u6578\u64da\u5eab\uff0c\u7bc0\u7701\u4e86\u7cfb\u7d71\u8cc7\u6e90\u3002<\/li>\n<li><strong>\u9748\u6d3b\u6027\uff1a<\/strong>\u7528\u6236\u53ef\u4ee5\u6839\u64da\u9700\u8981\u96a8\u6642\u555f\u52d5\u6216\u505c\u6b62\u6578\u64da\u5eab\u5be6\u4f8b\uff0c\u9748\u6d3b\u61c9\u5c0d\u4e0d\u540c\u7684\u9700\u6c42\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%b5%90%e8%ab%96-LqPJbMGayK\">\u7d50\u8ad6<\/h2>\n<p>\u7121\u9700\u5b89\u88dd\u7684\u6578\u64da\u5eab\u64cd\u4f5c\u547d\u4ee4\u70ba\u958b\u767c\u8005\u548c\u7cfb\u7d71\u7ba1\u7406\u54e1\u63d0\u4f9b\u4e86\u4e00\u7a2e\u9ad8\u6548\u3001\u9748\u6d3b\u7684\u6578\u64da\u5eab\u7ba1\u7406\u65b9\u5f0f\u3002\u901a\u904e\u4f7f\u7528 Docker \u548c\u5176\u4ed6\u8f15\u91cf\u7d1a\u7684\u6578\u64da\u5eab\u6280\u8853\uff0c\u7528\u6236\u53ef\u4ee5\u5feb\u901f\u90e8\u7f72\u548c\u64cd\u4f5c\u6578\u64da\u5eab\uff0c\u5f9e\u800c\u5c08\u6ce8\u65bc\u61c9\u7528\u7a0b\u5e8f\u7684\u958b\u767c\u548c\u6578\u64da\u7684\u5206\u6790\u3002\u5c0d\u65bc\u9700\u8981\u9ad8\u6548\u6578\u64da\u8655\u7406\u7684\u4f01\u696d\u4f86\u8aaa\uff0c\u9019\u7a2e\u65b9\u6cd5\u7121\u7591\u662f\u672a\u4f86\u7684\u8da8\u52e2\u3002<\/p>\n<p>\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u53ef\u9760\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u89e3\u6c7a\u65b9\u6848\u4f86\u652f\u6301\u60a8\u7684\u6578\u64da\u5eab\u64cd\u4f5c\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\u985e\u578b\u7684 <a href=\"https:\/\/server.hk\">\u4e91\u670d\u52a1\u5668<\/a>\uff0c\u6211\u5011\u90fd\u80fd\u70ba\u60a8\u63d0\u4f9b\u7a69\u5b9a\u7684\u670d\u52d9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63a2\u7d22\u7121\u9700\u5b89\u88dd\u7684\u6578\u64da\u5eab\u64cd\u4f5c\u547d\u4ee4\uff0c\u8f15\u9b06\u7ba1\u7406\u6578\u64da\u5eab\uff0c\u63d0\u5347\u5de5\u4f5c\u6548\u7387\uff0c\u9069\u5408\u5404\u985e\u7528\u6236\u4f7f\u7528\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-190678","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/190678","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=190678"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/190678\/revisions"}],"predecessor-version":[{"id":190679,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/190678\/revisions\/190679"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=190678"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=190678"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=190678"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}