{"id":76114,"date":"2024-10-16T03:58:16","date_gmt":"2024-10-15T19:58:16","guid":{"rendered":"https:\/\/server.hk\/cnblog\/76114\/"},"modified":"2024-10-16T03:58:16","modified_gmt":"2024-10-15T19:58:16","slug":"mysql%e5%91%bd%e4%bb%a4%e5%a4%a7%e5%85%a8%e7%b6%93%e5%85%b8%e7%89%88","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/76114\/","title":{"rendered":"MySQL\u547d\u4ee4\u5927\u5168\u7d93\u5178\u7248"},"content":{"rendered":"<h1 id=\"mysql%e5%91%bd%e4%bb%a4%e5%a4%a7%e5%85%a8%e7%b6%93%e5%85%b8%e7%89%88-gfaubnJuQr\">MySQL\u547d\u4ee4\u5927\u5168\u7d93\u5178\u7248<\/h1>\n<p>MySQL\u662f\u4e00\u7a2e\u6d41\u884c\u7684\u958b\u6e90\u95dc\u806f\u6578\u64da\u5eab\u7ba1\u7406\u7cfb\u7d71\uff0c\u5ee3\u6cdb\u61c9\u7528\u65bc\u5404\u7a2e\u7db2\u7ad9\u548c\u61c9\u7528\u7a0b\u5e8f\u4e2d\u3002\u7121\u8ad6\u662f\u958b\u767c\u8005\u9084\u662f\u6578\u64da\u5eab\u7ba1\u7406\u54e1\uff0c\u719f\u6089MySQL\u7684\u547d\u4ee4\u90fd\u662f\u5fc5\u4e0d\u53ef\u5c11\u7684\u3002\u672c\u6587\u5c07\u4ecb\u7d39\u4e00\u4e9b\u5e38\u7528\u7684MySQL\u547d\u4ee4\uff0c\u5e6b\u52a9\u8b80\u8005\u66f4\u597d\u5730\u7406\u89e3\u548c\u4f7f\u7528\u9019\u500b\u5f37\u5927\u7684\u6578\u64da\u5eab\u7cfb\u7d71\u3002<\/p>\n<h2 id=\"%e5%9f%ba%e6%9c%ac%e5%91%bd%e4%bb%a4-gfaubnJuQr\">\u57fa\u672c\u547d\u4ee4<\/h2>\n<h3 id=\"%e9%80%a3%e6%8e%a5%e5%88%b0mysql%e6%95%b8%e6%93%9a%e5%ba%ab-gfaubnJuQr\">\u9023\u63a5\u5230MySQL\u6578\u64da\u5eab<\/h3>\n<p>\u8981\u9023\u63a5\u5230MySQL\u6578\u64da\u5eab\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre><code>mysql -u username -p<\/code><\/pre>\n<p>\u5728\u9019\u88e1\uff0c<code>username<\/code>\u662f\u4f60\u7684MySQL\u7528\u6236\u540d\uff0c\u57f7\u884c\u5f8c\u7cfb\u7d71\u6703\u63d0\u793a\u4f60\u8f38\u5165\u5bc6\u78bc\u3002<\/p>\n<h3 id=\"%e6%9f%a5%e7%9c%8b%e6%95%b8%e6%93%9a%e5%ba%ab-gfaubnJuQr\">\u67e5\u770b\u6578\u64da\u5eab<\/h3>\n<p>\u9023\u63a5\u6210\u529f\u5f8c\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u67e5\u770b\u7576\u524d\u7684\u6578\u64da\u5eab\uff1a<\/p>\n<pre><code>SHOW DATABASES;<\/code><\/pre>\n<h3 id=\"%e9%81%b8%e6%93%87%e6%95%b8%e6%93%9a%e5%ba%ab-gfaubnJuQr\">\u9078\u64c7\u6578\u64da\u5eab<\/h3>\n<p>\u8981\u9078\u64c7\u4e00\u500b\u6578\u64da\u5eab\u9032\u884c\u64cd\u4f5c\uff0c\u53ef\u4ee5\u4f7f\u7528\uff1a<\/p>\n<pre><code>USE database_name;<\/code><\/pre>\n<p>\u5c07<code>database_name<\/code>\u66ff\u63db\u70ba\u4f60\u60f3\u8981\u4f7f\u7528\u7684\u6578\u64da\u5eab\u540d\u7a31\u3002<\/p>\n<h2 id=\"%e6%95%b8%e6%93%9a%e8%a1%a8%e6%93%8d%e4%bd%9c-gfaubnJuQr\">\u6578\u64da\u8868\u64cd\u4f5c<\/h2>\n<h3 id=\"%e6%9f%a5%e7%9c%8b%e6%95%b8%e6%93%9a%e8%a1%a8-gfaubnJuQr\">\u67e5\u770b\u6578\u64da\u8868<\/h3>\n<p>\u8981\u67e5\u770b\u7576\u524d\u6578\u64da\u5eab\u4e2d\u7684\u6240\u6709\u6578\u64da\u8868\uff0c\u53ef\u4ee5\u4f7f\u7528\uff1a<\/p>\n<pre><code>SHOW TABLES;<\/code><\/pre>\n<h3 id=\"%e5%89%b5%e5%bb%ba%e6%95%b8%e6%93%9a%e8%a1%a8-gfaubnJuQr\">\u5275\u5efa\u6578\u64da\u8868<\/h3>\n<p>\u5275\u5efa\u4e00\u500b\u65b0\u7684\u6578\u64da\u8868\u7684\u57fa\u672c\u8a9e\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre><code>CREATE TABLE table_name (\n    column1 datatype,\n    column2 datatype,\n    ...\n);<\/code><\/pre>\n<p>\u4f8b\u5982\uff0c\u5275\u5efa\u4e00\u500b\u540d\u70ba<code>users<\/code>\u7684\u8868\uff1a<\/p>\n<pre><code>CREATE TABLE users (\n    id INT AUTO_INCREMENT PRIMARY KEY,\n    username VARCHAR(50),\n    password VARCHAR(50)\n);<\/code><\/pre>\n<h3 id=\"%e5%88%aa%e9%99%a4%e6%95%b8%e6%93%9a%e8%a1%a8-gfaubnJuQr\">\u522a\u9664\u6578\u64da\u8868<\/h3>\n<p>\u8981\u522a\u9664\u4e00\u500b\u6578\u64da\u8868\uff0c\u53ef\u4ee5\u4f7f\u7528\uff1a<\/p>\n<pre><code>DROP TABLE table_name;<\/code><\/pre>\n<h2 id=\"%e6%95%b8%e6%93%9a%e6%93%8d%e4%bd%9c-gfaubnJuQr\">\u6578\u64da\u64cd\u4f5c<\/h2>\n<h3 id=\"%e6%8f%92%e5%85%a5%e6%95%b8%e6%93%9a-gfaubnJuQr\">\u63d2\u5165\u6578\u64da<\/h3>\n<p>\u63d2\u5165\u6578\u64da\u7684\u57fa\u672c\u8a9e\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre><code>INSERT INTO table_name (column1, column2, ...)\nVALUES (value1, value2, ...);<\/code><\/pre>\n<p>\u4f8b\u5982\uff0c\u5411<code>users<\/code>\u8868\u4e2d\u63d2\u5165\u4e00\u689d\u6578\u64da\uff1a<\/p>\n<pre><code>INSERT INTO users (username, password)\nVALUES ('testuser', 'testpass');<\/code><\/pre>\n<h3 id=\"%e6%9f%a5%e8%a9%a2%e6%95%b8%e6%93%9a-gfaubnJuQr\">\u67e5\u8a62\u6578\u64da<\/h3>\n<p>\u67e5\u8a62\u6578\u64da\u7684\u57fa\u672c\u8a9e\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre><code>SELECT column1, column2, ...\nFROM table_name\nWHERE condition;<\/code><\/pre>\n<p>\u4f8b\u5982\uff0c\u67e5\u8a62\u6240\u6709\u7528\u6236\uff1a<\/p>\n<pre><code>SELECT * FROM users;<\/code><\/pre>\n<h3 id=\"%e6%9b%b4%e6%96%b0%e6%95%b8%e6%93%9a-gfaubnJuQr\">\u66f4\u65b0\u6578\u64da<\/h3>\n<p>\u66f4\u65b0\u6578\u64da\u7684\u57fa\u672c\u8a9e\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre><code>UPDATE table_name\nSET column1 = value1, column2 = value2, ...\nWHERE condition;<\/code><\/pre>\n<p>\u4f8b\u5982\uff0c\u66f4\u65b0\u7528\u6236\u7684\u5bc6\u78bc\uff1a<\/p>\n<pre><code>UPDATE users\nSET password = 'newpass'\nWHERE username = 'testuser';<\/code><\/pre>\n<h3 id=\"%e5%88%aa%e9%99%a4%e6%95%b8%e6%93%9a-gfaubnJuQr\">\u522a\u9664\u6578\u64da<\/h3>\n<p>\u522a\u9664\u6578\u64da\u7684\u57fa\u672c\u8a9e\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre><code>DELETE FROM table_name\nWHERE condition;<\/code><\/pre>\n<p>\u4f8b\u5982\uff0c\u522a\u9664\u4e00\u500b\u7528\u6236\uff1a<\/p>\n<pre><code>DELETE FROM users\nWHERE username = 'testuser';<\/code><\/pre>\n<h2 id=\"%e7%b8%bd%e7%b5%90-gfaubnJuQr\">\u7e3d\u7d50<\/h2>\n<p>\u4ee5\u4e0a\u4ecb\u7d39\u4e86MySQL\u7684\u4e00\u4e9b\u57fa\u672c\u547d\u4ee4\uff0c\u9019\u4e9b\u547d\u4ee4\u662f\u6578\u64da\u5eab\u7ba1\u7406\u548c\u64cd\u4f5c\u7684\u57fa\u790e\u3002\u638c\u63e1\u9019\u4e9b\u547d\u4ee4\u5f8c\uff0c\u60a8\u5c07\u80fd\u5920\u66f4\u6709\u6548\u5730\u7ba1\u7406\u6578\u64da\u5eab\uff0c\u9032\u884c\u6578\u64da\u7684\u589e\u522a\u6539\u67e5\u3002\u5c0d\u65bc\u9700\u8981\u9ad8\u6548\u6578\u64da\u8655\u7406\u7684\u7528\u6236\uff0c\u9078\u64c7\u5408\u9069\u7684<a href=\"https:\/\/server.hk\">VPS<\/a>\u6216<a href=\"https:\/\/server.hk\">\u9999\u6e2f\u4f3a\u670d\u5668<\/a>\u53ef\u4ee5\u63d0\u4f9b\u66f4\u597d\u7684\u6027\u80fd\u548c\u7a69\u5b9a\u6027\u3002\u5e0c\u671b\u9019\u7bc7\u6587\u7ae0\u80fd\u5e6b\u52a9\u60a8\u5728MySQL\u7684\u4f7f\u7528\u4e0a\u66f4\u9032\u4e00\u6b65\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63a2\u7d22\u300aMySQL\u547d\u4ee4\u5927\u5168\u7d93\u5178\u7248\u300b\uff0c\u5168\u9762\u6db5\u84cbMySQL\u547d\u4ee4\uff0c\u52a9\u60a8\u9ad8\u6548\u7ba1\u7406\u6578\u64da\u5eab\uff0c\u63d0\u5347\u958b\u767c\u6280\u80fd\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-76114","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/76114","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=76114"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/76114\/revisions"}],"predecessor-version":[{"id":76115,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/76114\/revisions\/76115"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=76114"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=76114"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=76114"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}