{"id":80698,"date":"2024-10-16T14:40:17","date_gmt":"2024-10-16T06:40:17","guid":{"rendered":"https:\/\/server.hk\/cnblog\/80698\/"},"modified":"2024-10-16T14:40:18","modified_gmt":"2024-10-16T06:40:18","slug":"mysql%e5%ad%97%e6%ae%b5%e9%a1%9e%e5%9e%8b%e7%b0%a1%e4%bb%8b","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/80698\/","title":{"rendered":"MySQL\u5b57\u6bb5\u985e\u578b\u7c21\u4ecb"},"content":{"rendered":"<h1 id=\"mysql%e5%ad%97%e6%ae%b5%e9%a1%9e%e5%9e%8b%e7%b0%a1%e4%bb%8b-TkjOOTuffG\">MySQL\u5b57\u6bb5\u985e\u578b\u7c21\u4ecb<\/h1>\n<p>\u5728\u6578\u64da\u5eab\u8a2d\u8a08\u4e2d\uff0c\u9078\u64c7\u5408\u9069\u7684\u5b57\u6bb5\u985e\u578b\u5c0d\u65bc\u6578\u64da\u7684\u5b58\u5132\u548c\u67e5\u8a62\u6548\u7387\u81f3\u95dc\u91cd\u8981\u3002MySQL\u4f5c\u70ba\u4e00\u500b\u6d41\u884c\u7684\u958b\u6e90\u6578\u64da\u5eab\u7ba1\u7406\u7cfb\u7d71\uff0c\u63d0\u4f9b\u4e86\u591a\u7a2e\u5b57\u6bb5\u985e\u578b\u4ee5\u6eff\u8db3\u4e0d\u540c\u7684\u9700\u6c42\u3002\u672c\u6587\u5c07\u5c0dMySQL\u7684\u4e3b\u8981\u5b57\u6bb5\u985e\u578b\u9032\u884c\u7c21\u8981\u4ecb\u7d39\uff0c\u5e6b\u52a9\u958b\u767c\u8005\u5728\u8a2d\u8a08\u6578\u64da\u5eab\u6642\u505a\u51fa\u660e\u667a\u7684\u9078\u64c7\u3002<\/p>\n<h2 id=\"%e6%95%b8%e5%ad%97%e9%a1%9e%e5%9e%8b-TkjOOTuffG\">\u6578\u5b57\u985e\u578b<\/h2>\n<p>MySQL\u652f\u6301\u591a\u7a2e\u6578\u5b57\u985e\u578b\uff0c\u4e3b\u8981\u5206\u70ba\u6574\u6578\u985e\u578b\u548c\u6d6e\u9ede\u6578\u985e\u578b\u3002<\/p>\n<ul>\n<li><strong>\u6574\u6578\u985e\u578b\uff1a<\/strong>\u5305\u62ecTINYINT\u3001SMALLINT\u3001MEDIUMINT\u3001INT\u548cBIGINT\u3002\u9019\u4e9b\u985e\u578b\u7684\u5927\u5c0f\u548c\u7bc4\u570d\u5404\u4e0d\u76f8\u540c\uff0c\u9078\u64c7\u6642\u9700\u6839\u64da\u5be6\u969b\u9700\u6c42\u4f86\u6c7a\u5b9a\u3002\u4f8b\u5982\uff1a<\/li>\n<pre><code>CREATE TABLE example (\n        id INT NOT NULL AUTO_INCREMENT,\n        age TINYINT,\n        PRIMARY KEY (id)\n    );<\/code><\/pre>\n<li><strong>\u6d6e\u9ede\u6578\u985e\u578b\uff1a<\/strong>\u5305\u62ecFLOAT\u548cDOUBLE\uff0c\u9069\u5408\u5b58\u5132\u5e36\u5c0f\u6578\u7684\u6578\u5b57\u3002\u9019\u4e9b\u985e\u578b\u5728\u9032\u884c\u6578\u5b78\u8a08\u7b97\u6642\u975e\u5e38\u6709\u7528\u3002\u4f8b\u5982\uff1a<\/li>\n<pre><code>CREATE TABLE example (\n        price FLOAT,\n        discount DOUBLE\n    );<\/code><\/pre>\n<\/ul>\n<h2 id=\"%e5%ad%97%e7%ac%a6%e4%b8%b2%e9%a1%9e%e5%9e%8b-TkjOOTuffG\">\u5b57\u7b26\u4e32\u985e\u578b<\/h2>\n<p>\u5b57\u7b26\u4e32\u985e\u578b\u7528\u65bc\u5b58\u5132\u6587\u672c\u6578\u64da\uff0cMySQL\u63d0\u4f9b\u4e86\u591a\u7a2e\u9078\u64c7\uff1a<\/p>\n<ul>\n<li><strong>CHAR\uff1a<\/strong>\u56fa\u5b9a\u9577\u5ea6\u7684\u5b57\u7b26\u4e32\uff0c\u9069\u5408\u5b58\u5132\u9577\u5ea6\u4e00\u81f4\u7684\u6578\u64da\u3002<\/li>\n<li><strong>VARCHAR\uff1a<\/strong>\u53ef\u8b8a\u9577\u5ea6\u7684\u5b57\u7b26\u4e32\uff0c\u9069\u5408\u5b58\u5132\u9577\u5ea6\u4e0d\u4e00\u7684\u6578\u64da\uff0c\u6700\u5927\u9577\u5ea6\u53ef\u905465535\u5b57\u5143\u3002<\/li>\n<li><strong>TINYTEXT\u3001TEXT\u3001MEDIUMTEXT\u3001LONGTEXT\uff1a<\/strong>\u9019\u4e9b\u985e\u578b\u7528\u65bc\u5b58\u5132\u5927\u91cf\u6587\u672c\u6578\u64da\uff0c\u6839\u64da\u9700\u8981\u9078\u64c7\u5408\u9069\u7684\u985e\u578b\u3002<\/li>\n<\/ul>\n<p>\u4f8b\u5982\uff0c\u5275\u5efa\u4e00\u500b\u7528\u65bc\u5b58\u5132\u7528\u6236\u540d\u7684\u8868\uff1a<\/p>\n<pre><code>CREATE TABLE users (\n    username VARCHAR(50),\n    bio TEXT\n);<\/code><\/pre>\n<h2 id=\"%e6%97%a5%e6%9c%9f%e5%92%8c%e6%99%82%e9%96%93%e9%a1%9e%e5%9e%8b-TkjOOTuffG\">\u65e5\u671f\u548c\u6642\u9593\u985e\u578b<\/h2>\n<p>MySQL\u63d0\u4f9b\u4e86\u591a\u7a2e\u65e5\u671f\u548c\u6642\u9593\u985e\u578b\uff0c\u4e3b\u8981\u5305\u62ec\uff1a<\/p>\n<ul>\n<li><strong>DATE\uff1a<\/strong>\u7528\u65bc\u5b58\u5132\u65e5\u671f\uff0c\u683c\u5f0f\u70ba&#8217;YYYY-MM-DD&#8217;\u3002<\/li>\n<li><strong>TIME\uff1a<\/strong>\u7528\u65bc\u5b58\u5132\u6642\u9593\uff0c\u683c\u5f0f\u70ba&#8217;HH:MM:SS&#8217;\u3002<\/li>\n<li><strong>DATETIME\uff1a<\/strong>\u7528\u65bc\u5b58\u5132\u65e5\u671f\u548c\u6642\u9593\uff0c\u683c\u5f0f\u70ba&#8217;YYYY-MM-DD HH:MM:SS&#8217;\u3002<\/li>\n<li><strong>TIMESTAMP\uff1a<\/strong>\u81ea1970\u5e741\u67081\u65e5\u4ee5\u4f86\u7684\u79d2\u6578\uff0c\u9069\u5408\u7528\u65bc\u8a18\u9304\u4e8b\u4ef6\u7684\u6642\u9593\u6233\u3002<\/li>\n<\/ul>\n<p>\u4f8b\u5982\uff0c\u5275\u5efa\u4e00\u500b\u7528\u65bc\u5b58\u5132\u8a02\u55ae\u7684\u8868\uff1a<\/p>\n<pre><code>CREATE TABLE orders (\n    order_id INT,\n    order_date DATETIME\n);<\/code><\/pre>\n<h2 id=\"%e5%b8%83%e7%88%be%e9%a1%9e%e5%9e%8b-TkjOOTuffG\">\u5e03\u723e\u985e\u578b<\/h2>\n<p>MySQL\u4e2d\u7684\u5e03\u723e\u985e\u578b\u901a\u5e38\u4f7f\u7528TINYINT(1)\u4f86\u8868\u793a\uff0c0\u8868\u793a\u5047\uff0c1\u8868\u793a\u771f\u3002\u9019\u5728\u9700\u8981\u5b58\u5132\u662f\/\u5426\u6216\u958b\/\u95dc\u72c0\u614b\u6642\u975e\u5e38\u6709\u7528\u3002<\/p>\n<pre><code>CREATE TABLE settings (\n    is_active TINYINT(1)\n);<\/code><\/pre>\n<h2 id=\"%e7%b8%bd%e7%b5%90-TkjOOTuffG\">\u7e3d\u7d50<\/h2>\n<p>\u9078\u64c7\u5408\u9069\u7684MySQL\u5b57\u6bb5\u985e\u578b\u5c0d\u65bc\u6578\u64da\u5eab\u7684\u6027\u80fd\u548c\u53ef\u7dad\u8b77\u6027\u81f3\u95dc\u91cd\u8981\u3002\u4e86\u89e3\u5404\u7a2e\u5b57\u6bb5\u985e\u578b\u7684\u7279\u6027\u548c\u9069\u7528\u5834\u666f\uff0c\u53ef\u4ee5\u5e6b\u52a9\u958b\u767c\u8005\u5728\u8a2d\u8a08\u6578\u64da\u5eab\u6642\u505a\u51fa\u66f4\u597d\u7684\u6c7a\u7b56\u3002\u7121\u8ad6\u662f\u9078\u64c7\u6578\u5b57\u985e\u578b\u3001\u5b57\u7b26\u4e32\u985e\u578b\u9084\u662f\u65e5\u671f\u6642\u9593\u985e\u578b\uff0c\u6b63\u78ba\u7684\u9078\u64c7\u90fd\u80fd\u63d0\u9ad8\u6578\u64da\u7684\u5b58\u5132\u6548\u7387\u548c\u67e5\u8a62\u6027\u80fd\u3002<\/p>\n<p>\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u9ad8\u6548\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u89e3\u6c7a\u65b9\u6848\u4f86\u904b\u884c\u60a8\u7684MySQL\u6578\u64da\u5eab\uff0cServer.HK\u63d0\u4f9b\u591a\u7a2e\u9078\u64c7\uff0c\u6eff\u8db3\u60a8\u7684\u9700\u6c42\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e86\u89e3MySQL\u5b57\u6bb5\u7c7b\u578b\u7684\u57fa\u672c\u6982\u5ff5\uff0c\u5305\u62ec\u5e38\u7528\u6570\u636e\u7c7b\u578b\u53ca\u5176\u5e94\u7528\uff0c\u5e2e\u52a9\u60a8\u4f18\u5316\u6570\u636e\u5e93\u8bbe\u8ba1\u4e0e\u6027\u80fd\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-80698","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/80698","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=80698"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/80698\/revisions"}],"predecessor-version":[{"id":80699,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/80698\/revisions\/80699"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=80698"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=80698"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=80698"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}