{"id":154549,"date":"2024-11-02T16:44:22","date_gmt":"2024-11-02T08:44:22","guid":{"rendered":"https:\/\/server.hk\/cnblog\/154549\/"},"modified":"2024-11-02T16:44:23","modified_gmt":"2024-11-02T08:44:23","slug":"%e5%b0%8d-mysql-%e6%95%b8%e6%93%9a%e5%ba%ab%e4%b8%ad%e7%9a%84%e5%91%bd%e4%bb%a4%e5%82%99%e5%bf%98%e6%8f%8f%e8%bf%b0","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/154549\/","title":{"rendered":"\u5c0d MySQL \u6578\u64da\u5eab\u4e2d\u7684\u547d\u4ee4\u5099\u5fd8\u63cf\u8ff0"},"content":{"rendered":"<h1 id=\"%e5%b0%8d-mysql-%e6%95%b8%e6%93%9a%e5%ba%ab%e4%b8%ad%e7%9a%84%e5%91%bd%e4%bb%a4%e5%82%99%e5%bf%98%e6%8f%8f%e8%bf%b0-HYWVUxvJuw\">\u5c0d MySQL \u6578\u64da\u5eab\u4e2d\u7684\u547d\u4ee4\u5099\u5fd8\u63cf\u8ff0<\/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\u61c9\u7528\u7a0b\u5e8f\u4e2d\u3002\u7121\u8ad6\u662f\u5c0f\u578b\u7db2\u7ad9\u9084\u662f\u5927\u578b\u4f01\u696d\u7cfb\u7d71\uff0cMySQL \u90fd\u80fd\u63d0\u4f9b\u7a69\u5b9a\u548c\u9ad8\u6548\u7684\u6578\u64da\u5b58\u5132\u89e3\u6c7a\u65b9\u6848\u3002\u672c\u6587\u5c07\u5c0d MySQL \u4e2d\u7684\u4e00\u4e9b\u57fa\u672c\u547d\u4ee4\u9032\u884c\u5099\u5fd8\u63cf\u8ff0\uff0c\u5e6b\u52a9\u4f7f\u7528\u8005\u66f4\u597d\u5730\u7406\u89e3\u548c\u4f7f\u7528\u9019\u4e9b\u547d\u4ee4\u3002<\/p>\n<h2 id=\"1-%e5%9f%ba%e6%9c%ac%e5%91%bd%e4%bb%a4-HYWVUxvJuw\">1. \u57fa\u672c\u547d\u4ee4<\/h2>\n<h3 id=\"1-1-%e9%80%a3%e6%8e%a5%e5%88%b0-mysql-%e6%95%b8%e6%93%9a%e5%ba%ab-HYWVUxvJuw\">1.1 \u9023\u63a5\u5230 MySQL \u6578\u64da\u5eab<\/h3>\n<p>\u8981\u4f7f\u7528 MySQL\uff0c\u9996\u5148\u9700\u8981\u9023\u63a5\u5230\u6578\u64da\u5eab\u3002\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\u7684 MySQL \u7528\u6236\u540d\uff0c\u57f7\u884c\u5f8c\u7cfb\u7d71\u6703\u63d0\u793a\u4f60\u8f38\u5165\u5bc6\u78bc\u3002<\/p>\n<h3 id=\"1-2-%e6%9f%a5%e7%9c%8b%e6%95%b8%e6%93%9a%e5%ba%ab-HYWVUxvJuw\">1.2 \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=\"1-3-%e5%89%b5%e5%bb%ba%e6%95%b8%e6%93%9a%e5%ba%ab-HYWVUxvJuw\">1.3 \u5275\u5efa\u6578\u64da\u5eab<\/h3>\n<p>\u8981\u5275\u5efa\u4e00\u500b\u65b0\u7684\u6578\u64da\u5eab\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre><code>CREATE DATABASE database_name;<\/code><\/pre>\n<p>\u5c07 <code>database_name<\/code> \u66ff\u63db\u70ba\u4f60\u60f3\u8981\u7684\u6578\u64da\u5eab\u540d\u7a31\u3002<\/p>\n<h3 id=\"1-4-%e5%88%aa%e9%99%a4%e6%95%b8%e6%93%9a%e5%ba%ab-HYWVUxvJuw\">1.4 \u522a\u9664\u6578\u64da\u5eab<\/h3>\n<p>\u5982\u679c\u9700\u8981\u522a\u9664\u4e00\u500b\u6578\u64da\u5eab\uff0c\u53ef\u4ee5\u4f7f\u7528\uff1a<\/p>\n<pre><code>DROP DATABASE database_name;<\/code><\/pre>\n<h2 id=\"2-%e8%a1%a8%e6%93%8d%e4%bd%9c%e5%91%bd%e4%bb%a4-HYWVUxvJuw\">2. \u8868\u64cd\u4f5c\u547d\u4ee4<\/h2>\n<h3 id=\"2-1-%e5%89%b5%e5%bb%ba%e8%a1%a8-HYWVUxvJuw\">2.1 \u5275\u5efa\u8868<\/h3>\n<p>\u5728\u6578\u64da\u5eab\u4e2d\u5275\u5efa\u8868\u7684\u547d\u4ee4\u5982\u4e0b\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\u7528\u6236\u8868\uff1a<\/p>\n<pre><code>CREATE TABLE users (\n    id INT AUTO_INCREMENT PRIMARY KEY,\n    username VARCHAR(50) NOT NULL,\n    password VARCHAR(50) NOT NULL\n);<\/code><\/pre>\n<h3 id=\"2-2-%e6%9f%a5%e7%9c%8b%e8%a1%a8%e7%b5%90%e6%a7%8b-HYWVUxvJuw\">2.2 \u67e5\u770b\u8868\u7d50\u69cb<\/h3>\n<p>\u8981\u67e5\u770b\u8868\u7684\u7d50\u69cb\uff0c\u53ef\u4ee5\u4f7f\u7528\uff1a<\/p>\n<pre><code>DESCRIBE table_name;<\/code><\/pre>\n<h3 id=\"2-3-%e5%88%aa%e9%99%a4%e8%a1%a8-HYWVUxvJuw\">2.3 \u522a\u9664\u8868<\/h3>\n<p>\u522a\u9664\u8868\u7684\u547d\u4ee4\u70ba\uff1a<\/p>\n<pre><code>DROP TABLE table_name;<\/code><\/pre>\n<h2 id=\"3-%e6%95%b8%e6%93%9a%e6%93%8d%e4%bd%9c%e5%91%bd%e4%bb%a4-HYWVUxvJuw\">3. \u6578\u64da\u64cd\u4f5c\u547d\u4ee4<\/h2>\n<h3 id=\"3-1-%e6%8f%92%e5%85%a5%e6%95%b8%e6%93%9a-HYWVUxvJuw\">3.1 \u63d2\u5165\u6578\u64da<\/h3>\n<p>\u5411\u8868\u4e2d\u63d2\u5165\u6578\u64da\u7684\u547d\u4ee4\u5982\u4e0b\uff1a<\/p>\n<pre><code>INSERT INTO table_name (column1, column2, ...)\nVALUES (value1, value2, ...);<\/code><\/pre>\n<p>\u4f8b\u5982\uff1a<\/p>\n<pre><code>INSERT INTO users (username, password)\nVALUES ('user1', 'pass123');<\/code><\/pre>\n<h3 id=\"3-2-%e6%9f%a5%e8%a9%a2%e6%95%b8%e6%93%9a-HYWVUxvJuw\">3.2 \u67e5\u8a62\u6578\u64da<\/h3>\n<p>\u67e5\u8a62\u6578\u64da\u7684\u57fa\u672c\u547d\u4ee4\u70ba\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=\"3-3-%e6%9b%b4%e6%96%b0%e6%95%b8%e6%93%9a-HYWVUxvJuw\">3.3 \u66f4\u65b0\u6578\u64da<\/h3>\n<p>\u66f4\u65b0\u8868\u4e2d\u6578\u64da\u7684\u547d\u4ee4\u70ba\uff1a<\/p>\n<pre><code>UPDATE table_name\nSET column1 = value1, column2 = value2, ...\nWHERE condition;<\/code><\/pre>\n<h3 id=\"3-4-%e5%88%aa%e9%99%a4%e6%95%b8%e6%93%9a-HYWVUxvJuw\">3.4 \u522a\u9664\u6578\u64da<\/h3>\n<p>\u522a\u9664\u6578\u64da\u7684\u547d\u4ee4\u70ba\uff1a<\/p>\n<pre><code>DELETE FROM table_name\nWHERE condition;<\/code><\/pre>\n<h2 id=\"4-%e6%95%b8%e6%93%9a%e5%ba%ab%e7%ae%a1%e7%90%86%e5%91%bd%e4%bb%a4-HYWVUxvJuw\">4. \u6578\u64da\u5eab\u7ba1\u7406\u547d\u4ee4<\/h2>\n<h3 id=\"4-1-%e5%89%b5%e5%bb%ba%e7%94%a8%e6%88%b6-HYWVUxvJuw\">4.1 \u5275\u5efa\u7528\u6236<\/h3>\n<p>\u5275\u5efa\u65b0\u7528\u6236\u7684\u547d\u4ee4\u70ba\uff1a<\/p>\n<pre><code>CREATE USER 'username'@'host' IDENTIFIED BY 'password';<\/code><\/pre>\n<h3 id=\"4-2-%e8%b3%a6%e4%ba%88%e6%ac%8a%e9%99%90-HYWVUxvJuw\">4.2 \u8ce6\u4e88\u6b0a\u9650<\/h3>\n<p>\u8ce6\u4e88\u7528\u6236\u6b0a\u9650\u7684\u547d\u4ee4\u70ba\uff1a<\/p>\n<pre><code>GRANT ALL PRIVILEGES ON database_name.* TO 'username'@'host';<\/code><\/pre>\n<h3 id=\"4-3-%e5%88%aa%e9%99%a4%e7%94%a8%e6%88%b6-HYWVUxvJuw\">4.3 \u522a\u9664\u7528\u6236<\/h3>\n<p>\u522a\u9664\u7528\u6236\u7684\u547d\u4ee4\u70ba\uff1a<\/p>\n<pre><code>DROP USER 'username'@'host';<\/code><\/pre>\n<h2 id=\"%e7%b8%bd%e7%b5%90-HYWVUxvJuw\">\u7e3d\u7d50<\/h2>\n<p>\u672c\u6587\u4ecb\u7d39\u4e86 MySQL \u6578\u64da\u5eab\u4e2d\u7684\u4e00\u4e9b\u57fa\u672c\u547d\u4ee4\uff0c\u5305\u62ec\u6578\u64da\u5eab\u548c\u8868\u7684\u5275\u5efa\u3001\u6578\u64da\u7684\u63d2\u5165\u3001\u67e5\u8a62\u3001\u66f4\u65b0\u548c\u522a\u9664\u7b49\u64cd\u4f5c\u3002\u9019\u4e9b\u547d\u4ee4\u662f\u4f7f\u7528 MySQL \u9032\u884c\u6578\u64da\u7ba1\u7406\u7684\u57fa\u790e\uff0c\u638c\u63e1\u5b83\u5011\u5c07\u6709\u52a9\u65bc\u63d0\u9ad8\u6578\u64da\u5eab\u64cd\u4f5c\u7684\u6548\u7387\u3002\u82e5\u60a8\u9700\u8981\u66f4\u9ad8\u6548\u7684\u6578\u64da\u5eab\u89e3\u6c7a\u65b9\u6848\uff0c\u8003\u616e\u4f7f\u7528 <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u670d\u52d9\uff0c\u9019\u5c07\u70ba\u60a8\u7684\u61c9\u7528\u63d0\u4f9b\u7a69\u5b9a\u7684\u652f\u6301\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e86\u89e3 MySQL \u6578\u64da\u5eab\u4e2d\u7684\u5e38\u7528\u547d\u4ee4\uff0c\u63d0\u5347\u6578\u64da\u7ba1\u7406\u6548\u7387\uff0c\u5feb\u901f\u67e5\u8a62\u3001\u66f4\u65b0\u548c\u7dad\u8b77\u6578\u64da\u7684\u5be6\u7528\u5099\u5fd8\u9304\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-154549","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/154549","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=154549"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/154549\/revisions"}],"predecessor-version":[{"id":154550,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/154549\/revisions\/154550"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=154549"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=154549"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=154549"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}