{"id":199703,"date":"2025-05-06T08:51:41","date_gmt":"2025-05-06T00:51:41","guid":{"rendered":"https:\/\/server.hk\/cnblog\/199703\/"},"modified":"2025-05-06T08:51:41","modified_gmt":"2025-05-06T00:51:41","slug":"%e5%a6%82%e4%bd%95%e5%9c%a8mysql%e4%b8%ad%e4%bd%bf%e7%94%a8%e6%b3%a8%e9%87%8a","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/199703\/","title":{"rendered":"\u5982\u4f55\u5728MySQL\u4e2d\u4f7f\u7528\u6ce8\u91ca"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>\u5982\u4f55\u5728MySQL\u4e2d\u4f7f\u7528\u6ce8\u91ca<\/h1>\n<p>\u54c8\u55bd\uff01\u5927\u5bb6\u597d\uff0c\u5f88\u9ad8\u5174\u53c8\u89c1\u9762\u4e86\uff0c\u6211\u662f\u4e3b\u673a\u5b9d\u8d1d\u7684\u4e00\u540d\u4f5c\u8005\uff0c\u4eca\u5929\u7531\u6211\u7ed9\u5927\u5bb6\u5e26\u6765\u4e00\u7bc7\uff0c\u672c\u6587\u4e3b\u8981\u4f1a\u8bb2\u5230\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5e0c\u671b\u5927\u5bb6\u4e00\u8d77\u5b66\u4e60\u8fdb\u6b65\uff0c\u4e5f\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8\u3001\u70b9\u8d5e\u3001\u6536\u85cf\u3001\u8f6c\u53d1! \u4e0b\u9762\u5c31\u4e00\u8d77\u6765\u770b\u770b\u5427\uff01<\/p>\n<p>MySQL\u4e2d\u7684comment\u7528\u6cd5\uff0c\u9700\u8981\u5177\u4f53\u4ee3\u7801\u793a\u4f8b<\/p>\n<p>\u5728MySQL\u4e2d\uff0ccomment\u5373\u4e3a\u6ce8\u91ca\u3002\u6ce8\u91ca\u662f\u4e00\u79cd\u5728\u4ee3\u7801\u4e2d\u52a0\u5165\u8bf4\u660e\u6216\u8bf4\u660e\u7684\u6587\u672c\uff0c\u53ef\u4ee5\u589e\u52a0\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u548c\u53ef\u7ef4\u62a4\u6027\u3002\u5728MySQL\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u5728\u6570\u636e\u5e93\u3001\u8868\u3001\u5217\u4ee5\u53ca\u5b58\u50a8\u8fc7\u7a0b\u7b49\u5404\u4e2a\u5c42\u6b21\u4e0a\u6dfb\u52a0\u6ce8\u91ca\u3002<\/p>\n<p>MySQL\u4e2d\u7684comment\u4e3b\u8981\u6709\u4e24\u79cd\u7528\u9014\uff1a\u4e00\u662f\u7528\u4e8e\u7ed9\u6570\u636e\u5e93\u5bf9\u8c61\u6dfb\u52a0\u6ce8\u91ca\uff1b\u4e8c\u662f\u7528\u4e8e\u63cf\u8ff0\u5217\u7684\u6570\u636e\u7c7b\u578b\u548c\u7ea6\u675f\u6761\u4ef6\u3002\u4e0b\u9762\u5c06\u8be6\u7ec6\u8bb2\u89e3\u5176\u5177\u4f53\u7528\u6cd5\uff0c\u5e76\u9644\u4e0a\u76f8\u5e94\u7684\u4ee3\u7801\u793a\u4f8b\u3002<\/p>\n<ol>\n<li>\u7ed9\u6570\u636e\u5e93\u5bf9\u8c61\u6dfb\u52a0\u6ce8\u91ca<\/li>\n<\/ol>\n<p>1.1 \u7ed9\u6570\u636e\u5e93\u6dfb\u52a0\u6ce8\u91ca<\/p>\n<p>\u4f7f\u7528<code>CREATE DATABASE<\/code>\u8bed\u53e5\u65f6\uff0c\u53ef\u4ee5\u5728\u8bed\u53e5\u7684\u6700\u540e\u6dfb\u52a0<code>COMMENT<\/code>\u5173\u952e\u5b57\uff0c\u7136\u540e\u52a0\u4e0a\u6ce8\u91ca\u7684\u5185\u5bb9\u3002<\/p>\n<p>\u4f8b\u5982\uff0c\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a<code>testdb<\/code>\u7684\u6570\u636e\u5e93\uff0c\u5e76\u6dfb\u52a0\u6ce8\u91ca\uff1a<\/p>\n<pre>CREATE DATABASE testdb COMMENT 'This is a test database';<\/pre>\n<p>\u6267\u884c\u4ee5\u4e0a\u8bed\u53e5\u540e\uff0c<code>testdb<\/code>\u6570\u636e\u5e93\u5c31\u4f1a\u88ab\u521b\u5efa\uff0c\u5e76\u5e26\u6709\u6ce8\u91ca&#8221;This is a test database&#8221;\u3002<\/p>\n<p>1.2 \u7ed9\u8868\u6dfb\u52a0\u6ce8\u91ca<\/p>\n<p>\u4f7f\u7528<code>CREATE TABLE<\/code>\u8bed\u53e5\u65f6\uff0c\u53ef\u4ee5\u5728\u8868\u540d\u540e\u9762\u4f7f\u7528<code>COMMENT<\/code>\u5173\u952e\u5b57\u6765\u4e3a\u8868\u6dfb\u52a0\u6ce8\u91ca\u3002<\/p>\n<p>\u4f8b\u5982\uff0c\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a<code>users<\/code>\u7684\u7528\u6237\u8868\uff0c\u5e76\u6dfb\u52a0\u6ce8\u91ca\uff1a<\/p>\n<pre>CREATE TABLE users (\n    id INT AUTO_INCREMENT PRIMARY KEY,\n    username VARCHAR(50) NOT NULL,\n    email VARCHAR(50) NOT NULL\n) COMMENT 'This table stores user information';<\/pre>\n<p>\u6267\u884c\u4ee5\u4e0a\u8bed\u53e5\u540e\uff0c<code>users<\/code>\u8868\u5c31\u4f1a\u88ab\u521b\u5efa\uff0c\u5e76\u5e26\u6709\u6ce8\u91ca&#8221;This table stores user information&#8221;\u3002<\/p>\n<p>1.3 \u7ed9\u5217\u6dfb\u52a0\u6ce8\u91ca<\/p>\n<p>\u4f7f\u7528<code>ALTER TABLE<\/code>\u8bed\u53e5\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528<code>MODIFY<\/code>\u5173\u952e\u5b57\u6765\u4e3a\u67d0\u4e00\u5217\u6dfb\u52a0\u6ce8\u91ca\u3002<\/p>\n<p>\u4f8b\u5982\uff0c\u4e3a<code>users<\/code>\u8868\u4e2d\u7684<code>username<\/code>\u5217\u6dfb\u52a0\u6ce8\u91ca\uff1a<\/p>\n<pre>ALTER TABLE users MODIFY username VARCHAR(50) COMMENT 'The username of the user';<\/pre>\n<p>\u6267\u884c\u4ee5\u4e0a\u8bed\u53e5\u540e\uff0c<code>users<\/code>\u8868\u4e2d\u7684<code>username<\/code>\u5217\u5c31\u4f1a\u5e26\u6709\u6ce8\u91ca&#8221;The username of the user&#8221;\u3002<\/p>\n<ol>\n<li>\u63cf\u8ff0\u5217\u7684\u6570\u636e\u7c7b\u578b\u548c\u7ea6\u675f\u6761\u4ef6<\/li>\n<\/ol>\n<p>\u5728\u521b\u5efa\u8868\u65f6\uff0c\u53ef\u4ee5\u5728\u5217\u7684\u6570\u636e\u7c7b\u578b\u540e\u4f7f\u7528<code>COMMENT<\/code>\u5173\u952e\u5b57\u6765\u63cf\u8ff0\u8be5\u5217\u7684\u7528\u9014\u3001\u9650\u5236\u6761\u4ef6\u7b49\u3002<\/p>\n<p>\u4f8b\u5982\uff0c\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a<code>orders<\/code>\u7684\u8ba2\u5355\u8868\uff0c\u5e76\u4e3a\u5176\u4e2d\u7684\u5217\u6dfb\u52a0\u6ce8\u91ca\uff1a<\/p>\n<pre>CREATE TABLE orders (\n    id INT AUTO_INCREMENT PRIMARY KEY COMMENT 'The ID of the order',\n    order_date DATE NOT NULL COMMENT 'The date the order is created',\n    customer_id INT NOT NULL COMMENT 'The ID of the customer'\n);<\/pre>\n<p>\u6267\u884c\u4ee5\u4e0a\u8bed\u53e5\u540e\uff0c<code>orders<\/code>\u8868\u4e2d\u7684\u5217\u90fd\u4f1a\u5e26\u6709\u76f8\u5e94\u7684\u6ce8\u91ca\u3002<\/p>\n<p>\u603b\u7ed3\uff1a<\/p>\n<p>\u5728MySQL\u4e2d\uff0ccomment\u4f5c\u4e3a\u6ce8\u91ca\u7684\u4e00\u79cd\u5f62\u5f0f\uff0c\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u66f4\u597d\u5730\u7406\u89e3\u548c\u7ef4\u62a4\u6570\u636e\u5e93\u3002\u5b83\u53ef\u4ee5\u5e94\u7528\u4e8e\u6570\u636e\u5e93\u3001\u8868\u3001\u5217\u4ee5\u53ca\u5b58\u50a8\u8fc7\u7a0b\u7b49\u5404\u4e2a\u5c42\u6b21\u4e0a\u3002\u901a\u8fc7\u793a\u4f8b\u4ee3\u7801\uff0c\u6211\u4eec\u53ef\u4ee5\u6e05\u695a\u5730\u4e86\u89e3comment\u7684\u7528\u6cd5\uff0c\u5e76\u5728\u5b9e\u9645\u5f00\u53d1\u4e2d\u5e94\u7528\u3002<\/p>\n<p>\u7406\u8bba\u8981\u638c\u63e1\uff0c\u5b9e\u64cd\u4e0d\u80fd\u843d\uff01\u4ee5\u4e0a\u5173\u4e8e\u300a\u5982\u4f55\u5728MySQL\u4e2d\u4f7f\u7528\u6ce8\u91ca\u300b\u7684\u8be6\u7ec6\u4ecb\u7ecd\uff0c\u5927\u5bb6\u90fd\u638c\u63e1\u4e86\u5427\uff01\u5982\u679c\u60f3\u8981\u7ee7\u7eed\u63d0\u5347\u81ea\u5df1\u7684\u80fd\u529b\uff0c\u90a3\u4e48\u5c31\u6765\u5173\u6ce8\u4e3b\u673a\u5b9d\u8d1d\u516c\u4f17\u53f7\u5427\uff01<\/p>\n<dl>\n<dt>\n <\/dt>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u5728MySQL\u4e2d\u4f7f\u7528\u6ce8\u91ca \u54c8\u55bd&#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-199703","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/199703","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=199703"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/199703\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=199703"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=199703"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=199703"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}