{"id":76562,"date":"2024-10-16T07:50:15","date_gmt":"2024-10-15T23:50:15","guid":{"rendered":"https:\/\/server.hk\/cnblog\/76562\/"},"modified":"2024-10-16T07:50:16","modified_gmt":"2024-10-15T23:50:16","slug":"mysql%e6%95%b8%e6%93%9a%e5%ba%ab%e5%91%bd%e4%bb%a4%e7%9a%84%e5%9f%ba%e7%a4%8e%e7%b0%a1%e4%bb%8b","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/76562\/","title":{"rendered":"MySQL\u6578\u64da\u5eab\u547d\u4ee4\u7684\u57fa\u790e\u7c21\u4ecb"},"content":{"rendered":"<h1 id=\"mysql%e6%95%b8%e6%93%9a%e5%ba%ab%e5%91%bd%e4%bb%a4%e7%9a%84%e5%9f%ba%e7%a4%8e%e7%b0%a1%e4%bb%8b-wAqJufrbLl\">MySQL\u6578\u64da\u5eab\u547d\u4ee4\u7684\u57fa\u790e\u7c21\u4ecb<\/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\u5c0f\u578b\u9805\u76ee\u9084\u662f\u5927\u578b\u4f01\u696d\uff0cMySQL\u90fd\u80fd\u63d0\u4f9b\u7a69\u5b9a\u548c\u9ad8\u6548\u7684\u6578\u64da\u5b58\u5132\u89e3\u6c7a\u65b9\u6848\u3002\u672c\u6587\u5c07\u4ecb\u7d39\u4e00\u4e9b\u57fa\u672c\u7684MySQL\u6578\u64da\u5eab\u547d\u4ee4\uff0c\u5e6b\u52a9\u8b80\u8005\u66f4\u597d\u5730\u7406\u89e3\u548c\u4f7f\u7528\u9019\u4e00\u5f37\u5927\u7684\u5de5\u5177\u3002<\/p>\n<h2 id=\"1-%e9%80%a3%e6%8e%a5%e5%88%b0mysql%e6%95%b8%e6%93%9a%e5%ba%ab-wAqJufrbLl\">1. \u9023\u63a5\u5230MySQL\u6578\u64da\u5eab<\/h2>\n<p>\u5728\u4f7f\u7528MySQL\u4e4b\u524d\uff0c\u9996\u5148\u9700\u8981\u9023\u63a5\u5230\u6578\u64da\u5eab\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u9032\u884c\u9023\u63a5\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\u3002\u57f7\u884c\u6b64\u547d\u4ee4\u5f8c\uff0c\u7cfb\u7d71\u6703\u63d0\u793a\u4f60\u8f38\u5165\u5bc6\u78bc\u3002<\/p>\n<h2 id=\"2-%e5%89%b5%e5%bb%ba%e6%95%b8%e6%93%9a%e5%ba%ab-wAqJufrbLl\">2. \u5275\u5efa\u6578\u64da\u5eab<\/h2>\n<p>\u9023\u63a5\u5230MySQL\u5f8c\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5275\u5efa\u4e00\u500b\u65b0\u7684\u6578\u64da\u5eab\uff1a<\/p>\n<pre><code>CREATE DATABASE database_name;<\/code><\/pre>\n<p>\u5c07<code>database_name<\/code>\u66ff\u63db\u70ba\u4f60\u5e0c\u671b\u5275\u5efa\u7684\u6578\u64da\u5eab\u540d\u7a31\u3002<\/p>\n<h2 id=\"3-%e6%9f%a5%e7%9c%8b%e6%95%b8%e6%93%9a%e5%ba%ab-wAqJufrbLl\">3. \u67e5\u770b\u6578\u64da\u5eab<\/h2>\n<p>\u8981\u67e5\u770b\u7576\u524d\u7cfb\u7d71\u4e2d\u7684\u6240\u6709\u6578\u64da\u5eab\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre><code>SHOW DATABASES;<\/code><\/pre>\n<h2 id=\"4-%e4%bd%bf%e7%94%a8%e6%95%b8%e6%93%9a%e5%ba%ab-wAqJufrbLl\">4. \u4f7f\u7528\u6578\u64da\u5eab<\/h2>\n<p>\u5728\u5275\u5efa\u6578\u64da\u5eab\u5f8c\uff0c\u9700\u8981\u9078\u64c7\u4f7f\u7528\u8a72\u6578\u64da\u5eab\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre><code>USE database_name;<\/code><\/pre>\n<h2 id=\"5-%e5%89%b5%e5%bb%ba%e8%a1%a8-wAqJufrbLl\">5. \u5275\u5efa\u8868<\/h2>\n<p>\u5728\u6578\u64da\u5eab\u4e2d\u5275\u5efa\u8868\u662f\u5b58\u5132\u6578\u64da\u7684\u7b2c\u4e00\u6b65\u3002\u4ee5\u4e0b\u662f\u5275\u5efa\u8868\u7684\u57fa\u672c\u8a9e\u6cd5\uff1a<\/p>\n<pre><code>CREATE TABLE table_name (\n    column1_name column1_datatype,\n    column2_name column2_datatype,\n    ...\n);<\/code><\/pre>\n<p>\u4f8b\u5982\uff0c\u5275\u5efa\u4e00\u500b\u540d\u70ba<code>users<\/code>\u7684\u8868\uff0c\u5305\u542b<code>id<\/code>\u548c<code>name<\/code>\u5169\u500b\u5b57\u6bb5\uff1a<\/p>\n<pre><code>CREATE TABLE users (\n    id INT AUTO_INCREMENT PRIMARY KEY,\n    name VARCHAR(100)\n);<\/code><\/pre>\n<h2 id=\"6-%e6%8f%92%e5%85%a5%e6%95%b8%e6%93%9a-wAqJufrbLl\">6. \u63d2\u5165\u6578\u64da<\/h2>\n<p>\u5275\u5efa\u8868\u5f8c\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u63d2\u5165\u6578\u64da\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 (name) VALUES ('Alice');<\/code><\/pre>\n<h2 id=\"7-%e6%9f%a5%e8%a9%a2%e6%95%b8%e6%93%9a-wAqJufrbLl\">7. \u67e5\u8a62\u6578\u64da<\/h2>\n<p>\u8981\u67e5\u8a62\u8868\u4e2d\u7684\u6578\u64da\uff0c\u53ef\u4ee5\u4f7f\u7528<code>SELECT<\/code>\u547d\u4ee4\uff1a<\/p>\n<pre><code>SELECT * FROM table_name;<\/code><\/pre>\n<p>\u9019\u5c07\u8fd4\u56de\u8868\u4e2d\u6240\u6709\u7684\u6578\u64da\u3002\u5982\u679c\u53ea\u60f3\u67e5\u8a62\u7279\u5b9a\u7684\u5217\uff0c\u53ef\u4ee5\u9019\u6a23\u5beb\uff1a<\/p>\n<pre><code>SELECT column1, column2 FROM table_name;<\/code><\/pre>\n<h2 id=\"8-%e6%9b%b4%e6%96%b0%e6%95%b8%e6%93%9a-wAqJufrbLl\">8. \u66f4\u65b0\u6578\u64da<\/h2>\n<p>\u5982\u679c\u9700\u8981\u66f4\u65b0\u8868\u4e2d\u7684\u6578\u64da\uff0c\u53ef\u4ee5\u4f7f\u7528<code>UPDATE<\/code>\u547d\u4ee4\uff1a<\/p>\n<pre><code>UPDATE table_name\nSET column1 = value1, column2 = value2, ...\nWHERE condition;<\/code><\/pre>\n<p>\u4f8b\u5982\uff0c\u5c07<code>users<\/code>\u8868\u4e2d<code>id<\/code>\u70ba1\u7684\u7528\u6236\u540d\u7a31\u66f4\u65b0\u70ba<code>Bob<\/code>\uff1a<\/p>\n<pre><code>UPDATE users SET name = 'Bob' WHERE id = 1;<\/code><\/pre>\n<h2 id=\"9-%e5%88%aa%e9%99%a4%e6%95%b8%e6%93%9a-wAqJufrbLl\">9. \u522a\u9664\u6578\u64da<\/h2>\n<p>\u8981\u522a\u9664\u8868\u4e2d\u7684\u6578\u64da\uff0c\u53ef\u4ee5\u4f7f\u7528<code>DELETE<\/code>\u547d\u4ee4\uff1a<\/p>\n<pre><code>DELETE FROM table_name WHERE condition;<\/code><\/pre>\n<p>\u4f8b\u5982\uff0c\u522a\u9664<code>users<\/code>\u8868\u4e2d<code>id<\/code>\u70ba1\u7684\u7528\u6236\uff1a<\/p>\n<pre><code>DELETE FROM users WHERE id = 1;<\/code><\/pre>\n<h2 id=\"%e7%b8%bd%e7%b5%90-wAqJufrbLl\">\u7e3d\u7d50<\/h2>\n<p>\u672c\u6587\u4ecb\u7d39\u4e86MySQL\u6578\u64da\u5eab\u7684\u4e00\u4e9b\u57fa\u672c\u547d\u4ee4\uff0c\u5305\u62ec\u9023\u63a5\u6578\u64da\u5eab\u3001\u5275\u5efa\u6578\u64da\u5eab\u548c\u8868\u3001\u63d2\u5165\u3001\u67e5\u8a62\u3001\u66f4\u65b0\u548c\u522a\u9664\u6578\u64da\u7b49\u3002\u9019\u4e9b\u547d\u4ee4\u662f\u4f7f\u7528MySQL\u9032\u884c\u6578\u64da\u7ba1\u7406\u7684\u57fa\u790e\uff0c\u638c\u63e1\u5b83\u5011\u5c07\u6709\u52a9\u65bc\u66f4\u9ad8\u6548\u5730\u64cd\u4f5c\u6578\u64da\u5eab\u3002<\/p>\n<p>\u5982\u679c\u4f60\u6b63\u5728\u5c0b\u627e\u7a69\u5b9a\u7684\u6578\u64da\u5eab\u89e3\u6c7a\u65b9\u6848\uff0c\u8003\u616e\u4f7f\u7528<a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a>\u4f86\u6258\u7ba1\u4f60\u7684MySQL\u6578\u64da\u5eab\uff0c\u4eab\u53d7\u9ad8\u6548\u7684\u6027\u80fd\u548c\u53ef\u9760\u7684\u652f\u6301\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e86\u89e3MySQL\u6578\u64da\u5eab\u547d\u4ee4\u7684\u57fa\u790e\u77e5\u8b58\uff0c\u638c\u63e1\u5e38\u7528\u6307\u4ee4\uff0c\u63d0\u5347\u6578\u64da\u7ba1\u7406\u8207\u67e5\u8a62\u6548\u7387\uff0c\u9069\u5408\u521d\u5b78\u8005\u8207\u958b\u767c\u8005\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-76562","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/76562","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=76562"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/76562\/revisions"}],"predecessor-version":[{"id":76563,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/76562\/revisions\/76563"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=76562"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=76562"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=76562"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}