{"id":200099,"date":"2025-05-06T08:25:02","date_gmt":"2025-05-06T00:25:02","guid":{"rendered":"https:\/\/server.hk\/cnblog\/200099\/"},"modified":"2025-05-06T08:25:02","modified_gmt":"2025-05-06T00:25:02","slug":"%e5%88%86%e6%9e%90mysql%e6%95%b0%e6%8d%ae%e5%ba%93%e7%ae%a1%e7%90%86%e7%b3%bb%e7%bb%9f%e7%9a%84%e5%9f%ba%e6%9c%ac%e5%8e%9f%e7%90%86","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/200099\/","title":{"rendered":"\u5206\u6790MySQL\u6570\u636e\u5e93\u7ba1\u7406\u7cfb\u7edf\u7684\u57fa\u672c\u539f\u7406"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>\u5206\u6790MySQL\u6570\u636e\u5e93\u7ba1\u7406\u7cfb\u7edf\u7684\u57fa\u672c\u539f\u7406<\/h1>\n<p>MySQL \u6570\u636e\u5e93\u7ba1\u7406\u7cfb\u7edf (DBMS) \u662f\u4e00\u4e2a\u5173\u7cfb\u578b\u6570\u636e\u5e93\uff0c\u4f7f\u7528 SQL \u8fdb\u884c\u6570\u636e\u5b58\u50a8\u548c\u7ba1\u7406\u3002\u672c\u6587\u5c06\u4ecb\u7ecd MySQL DBMS \u7684\u57fa\u672c\u539f\u7406\uff0c\u5305\u62ec\u6570\u636e\u5e93\u521b\u5efa\u3001\u6570\u636e\u8868\u8bbe\u8ba1\u3001\u6570\u636e\u589e\u5220\u6539\u67e5\u64cd\u4f5c\u548c\u8fde\u63a5\u6570\u636e\u5e93\u7684\u4ee3\u7801\u793a\u4f8b\u3002\u901a\u8fc7\u5b66\u4e60\u8fd9\u4e9b\u539f\u7406\uff0c\u8bfb\u8005\u53ef\u4ee5\u66f4\u597d\u5730\u7406\u89e3\u548c\u5e94\u7528 MySQL DBMS\u3002<\/p>\n<p>MySQL\u6570\u636e\u5e93\u7ba1\u7406\u7cfb\u7edf\u7684\u57fa\u672c\u539f\u7406\u89e3\u6790<\/p>\n<p>MySQL\u662f\u4e00\u79cd\u5e38\u7528\u7684\u5173\u7cfb\u578b\u6570\u636e\u5e93\u7ba1\u7406\u7cfb\u7edf\uff0c\u5b83\u901a\u8fc7\u7ed3\u6784\u5316\u67e5\u8be2\u8bed\u8a00\uff08SQL\uff09\u6765\u8fdb\u884c\u6570\u636e\u5b58\u50a8\u548c\u7ba1\u7406\u3002\u672c\u6587\u5c06\u4ecb\u7ecdMySQL\u6570\u636e\u5e93\u7ba1\u7406\u7cfb\u7edf\u7684\u57fa\u672c\u539f\u7406\uff0c\u5305\u62ec\u6570\u636e\u5e93\u7684\u521b\u5efa\u3001\u6570\u636e\u8868\u7684\u8bbe\u8ba1\u3001\u6570\u636e\u7684\u589e\u5220\u6539\u67e5\u7b49\u64cd\u4f5c\uff0c\u5e76\u63d0\u4f9b\u5177\u4f53\u7684\u4ee3\u7801\u793a\u4f8b\u3002<\/p>\n<p>\u4e00\u3001\u6570\u636e\u5e93\u7684\u521b\u5efa<\/p>\n<p>\u5728MySQL\u4e2d\uff0c\u9996\u5148\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u6570\u636e\u5e93\u5b9e\u4f8b\u6765\u5b58\u50a8\u6570\u636e\u3002\u901a\u8fc7\u4ee5\u4e0b\u4ee3\u7801\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a&#8221;mydatabase&#8221;\u7684\u6570\u636e\u5e93\uff1a<\/p>\n<pre>CREATE DATABASE mydatabase;<\/pre>\n<p>\u4e8c\u3001\u6570\u636e\u8868\u7684\u8bbe\u8ba1<\/p>\n<p>\u6570\u636e\u5e93\u4e2d\u7684\u6570\u636e\u901a\u5e38\u88ab\u7ec4\u7ec7\u6210\u6570\u636e\u8868\uff0c\u6570\u636e\u8868\u7531\u591a\u4e2a\u5b57\u6bb5\u7ec4\u6210\u3002\u901a\u8fc7\u4ee5\u4e0b\u4ee3\u7801\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a&#8221;users&#8221;\u7684\u6570\u636e\u8868\uff0c\u5305\u542bid\u3001name\u548cemail\u5b57\u6bb5\uff1a<\/p>\n<pre>USE mydatabase;\n\nCREATE TABLE users (\n    id INT PRIMARY KEY,\n    name VARCHAR(50),\n    email VARCHAR(50)\n);<\/pre>\n<p>\u4e09\u3001\u6570\u636e\u7684\u589e\u5220\u6539\u67e5<\/p>\n<ol>\n<li>\u63d2\u5165\u6570\u636e\uff1a<\/li>\n<\/ol>\n<p>\u53ef\u4ee5\u4f7f\u7528INSERT INTO\u8bed\u53e5\u6765\u5411\u6570\u636e\u8868\u4e2d\u63d2\u5165\u6570\u636e\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre>INSERT INTO users (id, name, email) VALUES (1, 'Alice', 'alice@example.com');<\/pre>\n<ol>\n<li>\u67e5\u8be2\u6570\u636e\uff1a<\/li>\n<\/ol>\n<p>\u53ef\u4ee5\u4f7f\u7528SELECT\u8bed\u53e5\u6765\u67e5\u8be2\u6570\u636e\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre>SELECT * FROM users;<\/pre>\n<ol>\n<li>\u66f4\u65b0\u6570\u636e\uff1a<\/li>\n<\/ol>\n<p>\u53ef\u4ee5\u4f7f\u7528UPDATE\u8bed\u53e5\u6765\u66f4\u65b0\u6570\u636e\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre>UPDATE users SET email='alice@example.org' WHERE id=1;<\/pre>\n<ol>\n<li>\u5220\u9664\u6570\u636e\uff1a<\/li>\n<\/ol>\n<p>\u53ef\u4ee5\u4f7f\u7528DELETE\u8bed\u53e5\u6765\u5220\u9664\u6570\u636e\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre>DELETE FROM users WHERE id=1;<\/pre>\n<p>\u56db\u3001\u8fde\u63a5\u6570\u636e\u5e93<\/p>\n<p>\u5728\u5e94\u7528\u7a0b\u5e8f\u4e2d\u8fde\u63a5MySQL\u6570\u636e\u5e93\u9700\u8981\u4f7f\u7528\u76f8\u5e94\u7684\u9a71\u52a8\u7a0b\u5e8f\uff0c\u5982MySQL\u5b98\u65b9\u63d0\u4f9b\u7684MySQL Connector\/J\u3002\u4ee5\u4e0b\u662f\u8fde\u63a5\u6570\u636e\u5e93\u5e76\u6267\u884c\u67e5\u8be2\u7684Java\u4ee3\u7801\u793a\u4f8b\uff1a<\/p>\n<pre>import java.sql.*;\n\npublic class Main {\n    public static void main(String[] args) {\n        String url = \"jdbc:mysql:\/\/localhost:3306\/mydatabase\";\n        String username = \"root\";\n        String password = \"password\";\n\n        try {\n            Connection connection = DriverManager.getConnection(url, username, password);\n            Statement statement = connection.createStatement();\n            ResultSet resultSet = statement.executeQuery(\"SELECT * FROM users\");\n\n            while (resultSet.next()) {\n                int id = resultSet.getInt(\"id\");\n                String name = resultSet.getString(\"name\");\n                String email = resultSet.getString(\"email\");\n                System.out.println(\"ID: \" + id + \", Name: \" + name + \", Email: \" + email);\n            }\n\n            connection.close();\n        } catch (SQLException e) {\n            e.printStackTrace();\n        }\n    }\n}<\/pre>\n<p>\u4ee5\u4e0a\u662fMySQL\u6570\u636e\u5e93\u7ba1\u7406\u7cfb\u7edf\u7684\u57fa\u672c\u539f\u7406\u89e3\u6790\u53ca\u76f8\u5173\u4ee3\u7801\u793a\u4f8b\u3002\u901a\u8fc7\u5b66\u4e60\u548c\u5b9e\u8df5\uff0c\u53ef\u4ee5\u66f4\u597d\u5730\u638c\u63e1MySQL\u6570\u636e\u5e93\u7ba1\u7406\u7cfb\u7edf\u7684\u4f7f\u7528\u548c\u5e94\u7528\u3002<\/p>\n<p>\u672c\u7bc7\u5173\u4e8e\u300a\u5206\u6790MySQL\u6570\u636e\u5e93\u7ba1\u7406\u7cfb\u7edf\u7684\u57fa\u672c\u539f\u7406\u300b\u7684\u4ecb\u7ecd\u5c31\u5230\u6b64\u7ed3\u675f\u5566\uff0c\u4f46\u662f\u5b66\u65e0\u6b62\u5883\uff0c\u60f3\u8981\u4e86\u89e3\u5b66\u4e60\u66f4\u591a\u5173\u4e8e\u6570\u636e\u5e93\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u8bf7\u5173\u6ce8\u4e3b\u673a\u5b9d\u8d1d\u516c\u4f17\u53f7\uff01<\/p>\n<dl>\n<dt>\n <\/dt>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>\u5206\u6790MySQL\u6570\u636e\u5e93\u7ba1\u7406\u7cfb\u7edf\u7684\u57fa&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-200099","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/200099","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"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=200099"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/200099\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=200099"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=200099"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=200099"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}