{"id":200042,"date":"2025-05-06T10:54:22","date_gmt":"2025-05-06T02:54:22","guid":{"rendered":"https:\/\/server.hk\/cnblog\/200042\/"},"modified":"2025-05-06T10:54:22","modified_gmt":"2025-05-06T02:54:22","slug":"mysql%e7%9a%84%e7%89%88%e6%9c%ac%e6%9c%89%e5%93%aa%e4%ba%9b%e7%a7%8d%e7%b1%bb%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/200042\/","title":{"rendered":"MySQL\u7684\u7248\u672c\u6709\u54ea\u4e9b\u79cd\u7c7b\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>MySQL\u7684\u7248\u672c\u6709\u54ea\u4e9b\u79cd\u7c7b\uff1f<\/h1>\n<p>\u4e0d\u77e5\u9053\u5927\u5bb6\u662f\u5426\u719f\u6089\uff1f\u4eca\u5929\u6211\u5c06\u7ed9\u5927\u5bb6\u4ecb\u7ecd\uff0c\u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u4f1a\u8bb2\u5230\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5982\u679c\u4f60\u5728\u770b\u5b8c\u672c\u7bc7\u6587\u7ae0\u540e\uff0c\u6709\u66f4\u597d\u7684\u5efa\u8bae\u6216\u8005\u53d1\u73b0\u54ea\u91cc\u6709\u95ee\u9898\uff0c\u5e0c\u671b\u5927\u5bb6\u90fd\u80fd\u79ef\u6781\u8bc4\u8bba\u6307\u51fa\uff0c\u8c22\u8c22\uff01\u5e0c\u671b\u6211\u4eec\u80fd\u4e00\u8d77\u52a0\u6cb9\u8fdb\u6b65\uff01<\/p>\n<p>MySQL\u662f\u4e00\u79cd\u6d41\u884c\u7684\u5f00\u6e90\u5173\u7cfb\u578b\u6570\u636e\u5e93\u7ba1\u7406\u7cfb\u7edf\uff0c\u62e5\u6709\u591a\u4e2a\u7248\u672c\uff0c\u6bcf\u4e2a\u7248\u672c\u90fd\u6709\u81ea\u5df1\u7684\u7279\u70b9\u548c\u529f\u80fd\u3002\u5728\u672c\u6587\u4e2d\uff0c\u6211\u4eec\u5c06\u4ecb\u7ecd\u4e00\u4e9b\u5e38\u89c1\u7684MySQL\u7248\u672c\uff0c\u5e76\u9644\u4e0a\u76f8\u5e94\u7684\u4ee3\u7801\u793a\u4f8b\u3002<\/p>\n<ol>\n<li>MySQL Community Edition\uff1a<br \/>MySQL Community Edition \u662fMySQL\u5b98\u65b9\u53d1\u5e03\u7684\u514d\u8d39\u7248\u672c\uff0c\u9002\u7528\u4e8e\u4e2a\u4eba\u7528\u6237\u548c\u5c0f\u578b\u56e2\u961f\u4f7f\u7528\u3002\u5b83\u5305\u542b\u4e86\u57fa\u672c\u7684\u6570\u636e\u5e93\u529f\u80fd\uff0c\u5982\u521b\u5efa\u8868\u3001\u63d2\u5165\u6570\u636e\u3001\u67e5\u8be2\u6570\u636e\u7b49\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u521b\u5efa\u8868\u7684\u793a\u4f8b\u4ee3\u7801\uff1a<\/li>\n<\/ol>\n<pre>CREATE TABLE users (\n    id INT AUTO_INCREMENT PRIMARY KEY,\n    username VARCHAR(255) NOT NULL,\n    email VARCHAR(255) NOT NULL\n);<\/pre>\n<ol>\n<li>MySQL Enterprise Edition\uff1a<br \/>MySQL Enterprise Edition \u662fMySQL\u63d0\u4f9b\u7684\u5546\u4e1a\u7248\u672c\uff0c\u4e13\u4e3a\u4f01\u4e1a\u7ea7\u7528\u6237\u8bbe\u8ba1\u3002\u5b83\u5305\u542b\u4e86\u4f01\u4e1a\u7ea7\u7684\u5b89\u5168\u6027\u3001\u53ef\u9760\u6027\u548c\u6027\u80fd\u4f18\u5316\u529f\u80fd\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u4f7f\u7528MySQL Enterprise Edition\u7684\u9ad8\u7ea7\u5b89\u5168\u529f\u80fd\u793a\u4f8b\uff1a<\/li>\n<\/ol>\n<pre>CREATE USER 'admin'@'localhost' IDENTIFIED BY 'password';\nGRANT ALL PRIVILEGES ON *.* TO 'admin'@'localhost' WITH GRANT OPTION;\nFLUSH PRIVILEGES;<\/pre>\n<ol>\n<li>MySQL Cluster Edition\uff1a<br \/>MySQL Cluster Edition \u662fMySQL\u63d0\u4f9b\u7684\u9ad8\u53ef\u7528\u6027\u3001\u9ad8\u6269\u5c55\u6027\u7248\u672c\uff0c\u9002\u7528\u4e8e\u5927\u89c4\u6a21\u5206\u5e03\u5f0f\u5e94\u7528\u7a0b\u5e8f\u3002\u5b83\u91c7\u7528\u4e86\u591a\u4e3b\u590d\u5236\u6280\u672f\uff0c\u786e\u4fdd\u6570\u636e\u5728\u6574\u4e2a\u96c6\u7fa4\u4e2d\u7684\u540c\u6b65\u548c\u6545\u969c\u8f6c\u79fb\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u5728MySQL Cluster\u4e2d\u521b\u5efa\u96c6\u7fa4\u8868\u7684\u793a\u4f8b\u4ee3\u7801\uff1a<\/li>\n<\/ol>\n<pre>CREATE TABLE users (\n    id INT,\n    username VARCHAR(255),\n    email VARCHAR(255),\n    PRIMARY KEY (id)\n) ENGINE = NDBCLUSTER;<\/pre>\n<ol>\n<li>MySQL Embedded Edition\uff1a<br \/>MySQL Embedded Edition \u662fMySQL\u7684\u5d4c\u5165\u5f0f\u7248\u672c\uff0c\u53ef\u4ee5\u76f4\u63a5\u96c6\u6210\u5230\u5e94\u7528\u7a0b\u5e8f\u4e2d\uff0c\u65e0\u9700\u5355\u72ec\u90e8\u7f72\u6570\u636e\u5e93\u670d\u52a1\u5668\u3002\u5b83\u975e\u5e38\u9002\u5408\u7528\u4e8e\u5d4c\u5165\u5f0f\u8bbe\u5907\u548c\u5d4c\u5165\u5f0f\u7cfb\u7edf\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u5728Java\u5e94\u7528\u7a0b\u5e8f\u4e2d\u4f7f\u7528MySQL Embedded Edition\u7684\u793a\u4f8b\u4ee3\u7801\uff1a<\/li>\n<\/ol>\n<pre>import com.mysql.cj.jdbc.MysqlDataSource;\nimport java.sql.Connection;\nimport java.sql.Statement;\n\npublic class EmbeddedMySQLExample {\n    public static void main(String[] args) {\n        MysqlDataSource dataSource = new MysqlDataSource();\n        dataSource.setURL(\"jdbc:mysql:embedded:\/\/localhost\/mydatabase\");\n        dataSource.setUser(\"root\");\n        dataSource.setPassword(\"password\");\n        \n        try (Connection con = dataSource.getConnection(); Statement stmt = con.createStatement()) {\n            stmt.executeUpdate(\"CREATE TABLE users (id INT AUTO_INCREMENT PRIMARY KEY, username VARCHAR(255) NOT NULL)\");\n        } catch (Exception e) {\n            e.printStackTrace();\n        }\n    }\n}<\/pre>\n<p>\u603b\u7684\u6765\u8bf4\uff0cMySQL\u6709\u591a\u4e2a\u7248\u672c\u9002\u7528\u4e8e\u4e0d\u540c\u7684\u7528\u6237\u9700\u6c42\uff0c\u65e0\u8bba\u662f\u4e2a\u4eba\u5f00\u53d1\u8005\u3001\u4e2d\u5c0f\u578b\u4f01\u4e1a\u8fd8\u662f\u5927\u578b\u4f01\u4e1a\uff0c\u90fd\u53ef\u4ee5\u6839\u636e\u5b9e\u9645\u60c5\u51b5\u9009\u62e9\u9002\u5408\u81ea\u5df1\u7684\u7248\u672c\u6765\u6784\u5efa\u7a33\u5b9a\u53ef\u9760\u7684\u6570\u636e\u5e93\u7cfb\u7edf\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u672c\u6587\u7684\u5168\u90e8\u5185\u5bb9\u4e86\uff0c\u662f\u5426\u6709\u987a\u5229\u5e2e\u52a9\u4f60\u89e3\u51b3\u95ee\u9898\uff1f\u82e5\u662f\u80fd\u7ed9\u4f60\u5e26\u6765\u5b66\u4e60\u4e0a\u7684\u5e2e\u52a9\uff0c\u8bf7\u5927\u5bb6\u591a\u591a\u652f\u6301\u4e3b\u673a\u5b9d\u8d1d\uff01\u66f4\u591a\u5173\u4e8e\u6570\u636e\u5e93\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u4e5f\u53ef\u5173\u6ce8\u4e3b\u673a\u5b9d\u8d1d\u516c\u4f17\u53f7\u3002<\/p>\n<dl>\n<dt>\n <\/dt>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>MySQL\u7684\u7248\u672c\u6709\u54ea\u4e9b\u79cd\u7c7b\uff1f \u4e0d&#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-200042","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/200042","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=200042"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/200042\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=200042"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=200042"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=200042"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}