{"id":76416,"date":"2024-10-16T06:29:18","date_gmt":"2024-10-15T22:29:18","guid":{"rendered":"https:\/\/server.hk\/cnblog\/76416\/"},"modified":"2024-10-16T06:29:19","modified_gmt":"2024-10-15T22:29:19","slug":"mysql%e6%95%b8%e6%93%9a%e5%ba%ab%e5%b8%b8%e7%94%a8%e6%95%b8%e6%93%9a%e9%a1%9e%e5%9e%8b%e4%bb%8b%e7%b4%b9-mysql%e6%95%b8%e6%93%9a%e5%ba%ab%e4%b8%ad%e7%9a%84%e9%a1%9e%e5%9e%8b","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/76416\/","title":{"rendered":"MySQL\u6578\u64da\u5eab\u5e38\u7528\u6578\u64da\u985e\u578b\u4ecb\u7d39 (MySQL\u6578\u64da\u5eab\u4e2d\u7684\u985e\u578b)"},"content":{"rendered":"<h1 id=\"mysql%e6%95%b8%e6%93%9a%e5%ba%ab%e5%b8%b8%e7%94%a8%e6%95%b8%e6%93%9a%e9%a1%9e%e5%9e%8b%e4%bb%8b%e7%b4%b9-HftMHdudjX\">MySQL\u6578\u64da\u5eab\u5e38\u7528\u6578\u64da\u985e\u578b\u4ecb\u7d39<\/h1>\n<p>\u5728\u6578\u64da\u5eab\u8a2d\u8a08\u4e2d\uff0c\u9078\u64c7\u5408\u9069\u7684\u6578\u64da\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\u6578\u64da\u985e\u578b\u4ee5\u6eff\u8db3\u4e0d\u540c\u7684\u9700\u6c42\u3002\u672c\u6587\u5c07\u4ecb\u7d39MySQL\u4e2d\u5e38\u7528\u7684\u6578\u64da\u985e\u578b\uff0c\u5e6b\u52a9\u958b\u767c\u8005\u66f4\u597d\u5730\u7406\u89e3\u548c\u4f7f\u7528\u9019\u4e9b\u985e\u578b\u3002<\/p>\n<h2 id=\"%e6%95%b8%e6%93%9a%e9%a1%9e%e5%9e%8b%e6%a6%82%e8%bf%b0-HftMHdudjX\">\u6578\u64da\u985e\u578b\u6982\u8ff0<\/h2>\n<p>MySQL\u7684\u6578\u64da\u985e\u578b\u4e3b\u8981\u5206\u70ba\u4ee5\u4e0b\u5e7e\u985e\uff1a<\/p>\n<ul>\n<li><strong>\u6578\u503c\u985e\u578b<\/strong><\/li>\n<li><strong>\u65e5\u671f\u548c\u6642\u9593\u985e\u578b<\/strong><\/li>\n<li><strong>\u5b57\u7b26\u4e32\u985e\u578b<\/strong><\/li>\n<li><strong>\u4e8c\u9032\u5236\u985e\u578b<\/strong><\/li>\n<\/ul>\n<h2 id=\"1-%e6%95%b8%e5%80%bc%e9%a1%9e%e5%9e%8b-HftMHdudjX\">1. \u6578\u503c\u985e\u578b<\/h2>\n<p>\u6578\u503c\u985e\u578b\u7528\u65bc\u5b58\u5132\u6578\u5b57\u6578\u64da\uff0c\u6839\u64da\u6578\u5b57\u7684\u7bc4\u570d\u548c\u7cbe\u5ea6\uff0cMySQL\u63d0\u4f9b\u4e86\u591a\u7a2e\u9078\u64c7\uff1a<\/p>\n<ul>\n<li><strong>TINYINT<\/strong>: \u7bc4\u570d\u70ba -128 \u5230 127\uff08\u6709\u7b26\u865f\uff09\u6216 0 \u5230 255\uff08\u7121\u7b26\u865f\uff09\uff0c\u4f54\u7528 1 \u5b57\u7bc0\u3002<\/li>\n<li><strong>SMALLINT<\/strong>: \u7bc4\u570d\u70ba -32,768 \u5230 32,767\uff08\u6709\u7b26\u865f\uff09\u6216 0 \u5230 65,535\uff08\u7121\u7b26\u865f\uff09\uff0c\u4f54\u7528 2 \u5b57\u7bc0\u3002<\/li>\n<li><strong>MEDIUMINT<\/strong>: \u7bc4\u570d\u70ba -8,388,608 \u5230 8,388,607\uff08\u6709\u7b26\u865f\uff09\u6216 0 \u5230 16,777,215\uff08\u7121\u7b26\u865f\uff09\uff0c\u4f54\u7528 3 \u5b57\u7bc0\u3002<\/li>\n<li><strong>INT<\/strong>: \u7bc4\u570d\u70ba -2,147,483,648 \u5230 2,147,483,647\uff08\u6709\u7b26\u865f\uff09\u6216 0 \u5230 4,294,967,295\uff08\u7121\u7b26\u865f\uff09\uff0c\u4f54\u7528 4 \u5b57\u7bc0\u3002<\/li>\n<li><strong>BIGINT<\/strong>: \u7bc4\u570d\u70ba -9,223,372,036,854,775,808 \u5230 9,223,372,036,854,775,807\uff08\u6709\u7b26\u865f\uff09\u6216 0 \u5230 18,446,744,073,709,551,615\uff08\u7121\u7b26\u865f\uff09\uff0c\u4f54\u7528 8 \u5b57\u7bc0\u3002<\/li>\n<li><strong>FLOAT<\/strong>: \u7528\u65bc\u5b58\u5132\u6d6e\u9ede\u6578\uff0c\u4f54\u7528 4 \u5b57\u7bc0\u3002<\/li>\n<li><strong>DOUBLE<\/strong>: \u7528\u65bc\u5b58\u5132\u96d9\u7cbe\u5ea6\u6d6e\u9ede\u6578\uff0c\u4f54\u7528 8 \u5b57\u7bc0\u3002<\/li>\n<li><strong>DECIMAL(M, D)<\/strong>: \u7cbe\u78ba\u7684\u6578\u503c\u985e\u578b\uff0cM \u8868\u793a\u7e3d\u4f4d\u6578\uff0cD \u8868\u793a\u5c0f\u6578\u4f4d\u6578\u3002<\/li>\n<\/ul>\n<h3 id=\"%e7%a4%ba%e4%be%8b-HftMHdudjX\">\u793a\u4f8b<\/h3>\n<pre><code>CREATE TABLE example (\n    id INT AUTO_INCREMENT PRIMARY KEY,\n    age TINYINT,\n    salary DECIMAL(10, 2)\n);<\/code><\/pre>\n<h2 id=\"2-%e6%97%a5%e6%9c%9f%e5%92%8c%e6%99%82%e9%96%93%e9%a1%9e%e5%9e%8b-HftMHdudjX\">2. \u65e5\u671f\u548c\u6642\u9593\u985e\u578b<\/h2>\n<p>MySQL\u63d0\u4f9b\u4e86\u591a\u7a2e\u65e5\u671f\u548c\u6642\u9593\u985e\u578b\uff0c\u9069\u5408\u5b58\u5132\u6642\u9593\u76f8\u95dc\u7684\u6578\u64da\uff1a<\/p>\n<ul>\n<li><strong>DATE<\/strong>: \u5b58\u5132\u65e5\u671f\uff0c\u683c\u5f0f\u70ba &#8216;YYYY-MM-DD&#8217;\uff0c\u4f54\u7528 3 \u5b57\u7bc0\u3002<\/li>\n<li><strong>TIME<\/strong>: \u5b58\u5132\u6642\u9593\uff0c\u683c\u5f0f\u70ba &#8216;HH:MM:SS&#8217;\uff0c\u4f54\u7528 3 \u5b57\u7bc0\u3002<\/li>\n<li><strong>DATETIME<\/strong>: \u5b58\u5132\u65e5\u671f\u548c\u6642\u9593\uff0c\u683c\u5f0f\u70ba &#8216;YYYY-MM-DD HH:MM:SS&#8217;\uff0c\u4f54\u7528 8 \u5b57\u7bc0\u3002<\/li>\n<li><strong>TIMESTAMP<\/strong>: \u5b58\u5132\u6642\u9593\u6233\uff0c\u683c\u5f0f\u70ba &#8216;YYYY-MM-DD HH:MM:SS&#8217;\uff0c\u4f54\u7528 4 \u5b57\u7bc0\u3002<\/li>\n<li><strong>YEAR<\/strong>: \u5b58\u5132\u5e74\u4efd\uff0c\u683c\u5f0f\u70ba &#8216;YYYY&#8217;\uff0c\u4f54\u7528 1 \u5b57\u7bc0\u3002<\/li>\n<\/ul>\n<h3 id=\"%e7%a4%ba%e4%be%8b-HftMHdudjX\">\u793a\u4f8b<\/h3>\n<pre><code>CREATE TABLE events (\n    event_id INT AUTO_INCREMENT PRIMARY KEY,\n    event_date DATE,\n    event_time TIME\n);<\/code><\/pre>\n<h2 id=\"3-%e5%ad%97%e7%ac%a6%e4%b8%b2%e9%a1%9e%e5%9e%8b-HftMHdudjX\">3. \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(M)<\/strong>: \u56fa\u5b9a\u9577\u5ea6\u5b57\u7b26\u4e32\uff0cM \u70ba\u9577\u5ea6\uff0c\u6700\u5927 255 \u5b57\u7b26\u3002<\/li>\n<li><strong>VARCHAR(M)<\/strong>: \u53ef\u8b8a\u9577\u5ea6\u5b57\u7b26\u4e32\uff0cM \u70ba\u6700\u5927\u9577\u5ea6\uff0c\u6700\u5927 65,535 \u5b57\u7b26\u3002<\/li>\n<li><strong>TINYTEXT<\/strong>: \u6700\u591a 255 \u5b57\u7b26\u7684\u6587\u672c\u3002<\/li>\n<li><strong>TEXT<\/strong>: \u6700\u591a 65,535 \u5b57\u7b26\u7684\u6587\u672c\u3002<\/li>\n<li><strong>MEDIUMTEXT<\/strong>: \u6700\u591a 16,777,215 \u5b57\u7b26\u7684\u6587\u672c\u3002<\/li>\n<li><strong>LONGTEXT<\/strong>: \u6700\u591a 4,294,967,295 \u5b57\u7b26\u7684\u6587\u672c\u3002<\/li>\n<\/ul>\n<h3 id=\"%e7%a4%ba%e4%be%8b-HftMHdudjX\">\u793a\u4f8b<\/h3>\n<pre><code>CREATE TABLE users (\n    user_id INT AUTO_INCREMENT PRIMARY KEY,\n    username VARCHAR(50),\n    bio TEXT\n);<\/code><\/pre>\n<h2 id=\"4-%e4%ba%8c%e9%80%b2%e5%88%b6%e9%a1%9e%e5%9e%8b-HftMHdudjX\">4. \u4e8c\u9032\u5236\u985e\u578b<\/h2>\n<p>\u4e8c\u9032\u5236\u985e\u578b\u7528\u65bc\u5b58\u5132\u4e8c\u9032\u5236\u6578\u64da\uff0c\u5982\u5716\u50cf\u6216\u6587\u4ef6\uff1a<\/p>\n<ul>\n<li><strong>BINARY(M)<\/strong>: \u56fa\u5b9a\u9577\u5ea6\u4e8c\u9032\u5236\u6578\u64da\u3002<\/li>\n<li><strong>VARBINARY(M)<\/strong>: \u53ef\u8b8a\u9577\u5ea6\u4e8c\u9032\u5236\u6578\u64da\u3002<\/li>\n<li><strong>TINYBLOB<\/strong>: \u6700\u591a 255 \u5b57\u7bc0\u7684\u4e8c\u9032\u5236\u6578\u64da\u3002<\/li>\n<li><strong>BLOB<\/strong>: \u6700\u591a 65,535 \u5b57\u7bc0\u7684\u4e8c\u9032\u5236\u6578\u64da\u3002<\/li>\n<li><strong>MEDIUMBLOB<\/strong>: \u6700\u591a 16,777,215 \u5b57\u7bc0\u7684\u4e8c\u9032\u5236\u6578\u64da\u3002<\/li>\n<li><strong>LONGBLOB<\/strong>: \u6700\u591a 4,294,967,295 \u5b57\u7bc0\u7684\u4e8c\u9032\u5236\u6578\u64da\u3002<\/li>\n<\/ul>\n<h3 id=\"%e7%a4%ba%e4%be%8b-HftMHdudjX\">\u793a\u4f8b<\/h3>\n<pre><code>CREATE TABLE files (\n    file_id INT AUTO_INCREMENT PRIMARY KEY,\n    file_data LONGBLOB\n);<\/code><\/pre>\n<h2 id=\"%e7%b8%bd%e7%b5%90-HftMHdudjX\">\u7e3d\u7d50<\/h2>\n<p>\u9078\u64c7\u5408\u9069\u7684\u6578\u64da\u985e\u578b\u5c0d\u65bc\u6578\u64da\u5eab\u7684\u6027\u80fd\u548c\u5b58\u5132\u6548\u7387\u81f3\u95dc\u91cd\u8981\u3002MySQL\u63d0\u4f9b\u4e86\u591a\u7a2e\u6578\u64da\u985e\u578b\u4ee5\u6eff\u8db3\u4e0d\u540c\u7684\u9700\u6c42\uff0c\u958b\u767c\u8005\u61c9\u6839\u64da\u5be6\u969b\u60c5\u6cc1\u9078\u64c7\u5408\u9069\u7684\u985e\u578b\u3002\u4e86\u89e3\u9019\u4e9b\u6578\u64da\u985e\u578b\u7684\u7279\u6027\u548c\u4f7f\u7528\u5834\u666f\uff0c\u5c07\u6709\u52a9\u65bc\u66f4\u597d\u5730\u8a2d\u8a08\u548c\u512a\u5316\u6578\u64da\u5eab\u7d50\u69cb\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\uff0cServer.HK \u63d0\u4f9b\u591a\u7a2e\u9078\u64c7\uff0c\u9069\u5408\u5404\u7a2e\u9700\u6c42\u3002\u7121\u8ad6\u662f <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u9084\u662f\u5176\u4ed6\u670d\u52d9\uff0c\u6211\u5011\u90fd\u80fd\u70ba\u60a8\u63d0\u4f9b\u652f\u6301\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e86\u89e3MySQL\u6578\u64da\u5eab\u4e2d\u5e38\u7528\u7684\u6578\u64da\u985e\u578b\uff0c\u5305\u62ec\u6574\u6578\u3001\u6d6e\u9ede\u6578\u3001\u5b57\u7b26\u4e32\u548c\u65e5\u671f\u6642\u9593\uff0c\u5e6b\u52a9\u60a8\u9078\u64c7\u5408\u9069\u7684\u6578\u64da\u683c\u5f0f\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-76416","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/76416","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=76416"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/76416\/revisions"}],"predecessor-version":[{"id":76417,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/76416\/revisions\/76417"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=76416"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=76416"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=76416"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}