{"id":10008126,"date":"2023-08-21T13:00:31","date_gmt":"2023-08-21T05:00:31","guid":{"rendered":"https:\/\/blog.itmax.cn\/?p=10008126"},"modified":"2023-08-21T13:00:31","modified_gmt":"2023-08-21T05:00:31","slug":"%e9%ab%98%e6%80%a7%e8%83%bdmysql%e5%ae%9e%e6%88%98%ef%bc%88%e4%b8%80%ef%bc%89%ef%bc%9a%e8%a1%a8%e7%bb%93%e6%9e%84-%e4%ba%ac%e4%b8%9c%e7%89%a9%e6%b5%81%e6%8a%80%e6%9c%af%e5%9b%a2%e9%98%9f","status":"publish","type":"post","link":"https:\/\/itmax.cn\/?p=10008126","title":{"rendered":"\u9ad8\u6027\u80fdMySQL\u5b9e\u6218\uff08\u4e00\uff09\uff1a\u8868\u7ed3\u6784 | \u4eac\u4e1c\u7269\u6d41\u6280\u672f\u56e2\u961f"},"content":{"rendered":"<p>\u6700\u8fd1\u56e0\u9700\u6c42\u6539\u52a8\u65b0\u589e\u4e86\u4e00\u4e9b\u6570\u636e\u5e93\u8868\uff0c\u4f46\u662f\u5728\u5b9a\u4e49\u8868\u7ed3\u6784\u65f6\uff0c\u5177\u4f53\u5217\u5c5e\u6027\u7684\u9009\u62e9\u6709\u4e9b\u4e0d\u77e5\u5176\u6240\u4ee5\u7136\uff0c\u7d22\u5f15\u7684\u6dfb\u52a0\u4e5f\u6709\u9057\u6f0f\u548c\u4e0d\u89c4\u8303\u7684\u5730\u65b9\uff0c\u6240\u4ee5\u6211\u6253\u7b97\u4e3a\u521b\u5efa\u4e00\u4e2a\u9ad8\u6027\u80fd\u8868\u7684\u8fc7\u7a0b\u4ee5\u5b9e\u6218\u7684\u5f62\u5f0f\u5199\u4e00\u4e2a\u4e13\u9898\uff0c\u4ee5\u6b64\u6765\u5b66\u4e60\u548c\u5de9\u56fa\u8fd9\u4e9b\u77e5\u8bc6\u3002<\/p>\n<h2>1. \u5b9e\u6218<\/h2>\n<p>\u6211\u4f7f\u7528\u7684 MySQL \u7248\u672c\u662f 5.7\uff0c\u5efa\u8868 DDL \u8bed\u53e5\u5982\u4e0b\u6240\u793a\uff1a\u6839\u636e\u9700\u6c42\u521b\u5efa<strong>\u63a5\u53e3\u8c03\u7528\u65e5\u5fd7<\/strong>\u6570\u636e\u5e93\u8868\uff0c\u8bf7\u5927\u5bb6\u6d4f\u89c8\u5177\u4f53\u5b57\u6bb5\u7684\u5c5e\u6027\u4fe1\u606f\uff0c\u5b83\u4eec\u6709\u4e0d\u5c11\u80fd\u591f\u4f18\u5316\u7684\u70b9\u3002<\/p>\n<pre><code>CREATE TABLE `service_log` (\n  `id` bigint(100) NOT NULL AUTO_INCREMENT COMMENT '\u4e3b\u952e',\n  `service_type` int(10) DEFAULT NULL COMMENT '\u63a5\u53e3\u7c7b\u578b',\n  `service_name` varchar(30) DEFAULT NULL COMMENT '\u63a5\u53e3\u540d\u79f0',\n  `service_method` varchar(10) DEFAULT NULL COMMENT '\u63a5\u53e3\u65b9\u5f0f',\n  `serial_no` int(10) DEFAULT NULL COMMENT '\u6d88\u606f\u5e8f\u53f7',\n  `service_caller` varchar(15) DEFAULT NULL COMMENT '\u8c03\u7528\u65b9',\n  `service_receiver` varchar(15) DEFAULT NULL COMMENT '\u63a5\u6536\u65b9',\n  `status` int(3) DEFAULT '10' COMMENT '\u72b6\u6001 10-\u6210\u529f 20-\u5f02\u5e38',\n  `error_message` varchar(200) DEFAULT NULL COMMENT '\u5f02\u5e38\u4fe1\u606f',\n  `message` text DEFAULT NULL COMMENT '\u62a5\u6587\u5185\u5bb9',\n  `create_user` varchar(50) DEFAULT NULL COMMENT '\u521b\u5efa\u8005',\n  `create_time` datetime NOT NULL COMMENT '\u521b\u5efa\u65f6\u95f4',\n  `update_user` varchar(50) DEFAULT NULL COMMENT '\u66f4\u65b0\u8005',\n  `update_time` datetime NOT NULL COMMENT '\u66f4\u65b0\u65f6\u95f4',\n  `is_delete` tinyint(1) NOT NULL DEFAULT '0' COMMENT '\u522a\u9664\u6807\u5fd7',\n  `ts` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '\u65f6\u95f4\u6233',\n  PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='\u63a5\u53e3\u8c03\u7528\u65e5\u5fd7';\n\n\n<\/code><\/pre>\n<p>\u6211\u4f1a\u5728\u4e0b\u6587\u4e2d\u5c06\u5176\u4e2d\u5305\u542b\u7684\u95ee\u9898\u548c\u53ef\u4ee5\u8fdb\u884c\u4f18\u5316\u7684\u5730\u65b9\u4e00\u4e00\u8fdb\u884c\u89e3\u91ca\uff0c\u4e3b\u8981\u53c2\u8003\u7684\u4e66\u76ee\u662f\u300a\u9ad8\u6027\u80fdMySQL \u7b2c\u56db\u7248\u300b\uff0c\u4e5f\u5e0c\u671b\u5927\u5bb6\u6709\u7cbe\u529b\u53bb\u770b\u539f\u4e66\u3002<\/p>\n<h2>2. \u4f18\u5316\u548c\u6539\u8fdb<\/h2>\n<h4>\u6177\u6168\u4e0d\u662f\u660e\u667a\u7684<\/h4>\n<p>\u4e00\u822c\u6765\u8bf4\uff0c\u8981\u5c3d\u91cf\u4f7f\u7528\u80fd\u591f\u6b63\u786e\u5b58\u50a8\u548c\u8868\u793a\u6570\u636e\u7684\u6700\u5c0f\u6570\u636e\u7c7b\u578b\uff0c\u66f4\u5c0f\u7684\u6570\u636e\u7c7b\u578b\u901a\u5e38\u66f4\u5feb\uff0c\u56e0\u4e3a\u5b83\u4eec\u5360\u7528\u7684\u78c1\u76d8\u3001\u5185\u5b58\u548cCPU\u7f13\u5b58\u7684\u7a7a\u95f4\u66f4\u5c11\uff0c\u5e76\u4e14\u5904\u7406\u65f6\u9700\u8981\u7684CPU\u5468\u671f\u4e5f\u66f4\u5c11\u3002\u4f46\u662f\uff0c\u8fd9\u4e5f\u8981\u786e\u4fdd\u6ca1\u6709\u4f4e\u4f30\u9700\u8981\u5b58\u50a8\u7684\u503c\u7684\u8303\u56f4\uff0c\u5426\u5219\u4f1a\u56e0\u5165\u5e93\u5931\u8d25\u800c\u9020\u6210\u6570\u636e\u4e22\u5931\uff0c\u800c\u4e14\u8868\u7ed3\u6784\u4fee\u6539\u7684\u6d41\u7a0b\u5ba1\u6279\u4e5f\u5f88\u9ebb\u70e6\u3002<\/p>\n<p>\u6211\u4eec\u4ee5\u8868\u4e2d<code>id<\/code>\u548c<code>message<\/code>\u5217\u4e3a\u4f8b\u6765\u8bf4\uff1a<\/p>\n<p><code>id<\/code>\u4e3a\u4e3b\u952e\u5217\uff0c\u5b83\u4f7f\u7528\u7684\u662f\u6574\u6570\u7c7b\u578b BIGINT(64\u4f4d)\uff0c\u9664\u6b64\u4e4b\u5916\u8fd8\u6709 TINYINT(8\u4f4d)\u3001SMALLINT(16\u4f4d)\u3001MEDIUMINT(24\u4f4d) \u548c INT(32\u4f4d)\uff0c\u53ef\u4ee5\u5b58\u50a8\u7684\u53d6\u503c\u8303\u56f4\u662f\u4ece -2(N &#8211; 1)\u5230 2(N &#8211; 1)- 1\uff0c\u6240\u4ee5 BIGINT \u7c7b\u578b\u503c\u7684\u6700\u5927\u503c\u662f9223372036854775808(19\u4f4d\u6570)\u3002<\/p>\n<p>\u663e\u7136\uff0c\u4e3b\u952e\u5b9a\u4e49100\u4f4d\u5bbd\u5ea6\u662f\u6709\u4e9b\u201c\u65e0\u8111\u7684\u201d\uff0c\u800c\u4e14\u4e5f\u662f\u6ca1\u6709\u610f\u4e49\u7684\uff1a\u56e0\u4e3a<strong>\u5b83\u4e0d\u4f1a\u9650\u5236\u503c\u7684\u5408\u6cd5\u8303\u56f4<\/strong>\uff0c\u5373\u4f7f\u662f\u5b9a\u4e49\u4e86 BIGINT(100) \u4e5f\u6ca1\u529e\u6cd5\u5b58\u50a8\u5bbd\u5ea6\u4e3a100\u7684\u6570\u5b57\uff0c\u5b9e\u9645\u4e0a\u5b9a\u4e49 BIGINT(1) \u548c BIGINT(20) \u7684<strong>\u5b58\u50a8\u7a7a\u95f4\u662f\u76f8\u540c\u7684<\/strong>\uff0c\u5bbd\u5ea6\u7684\u5b9a\u4e49\u53ea\u662f\u89c4\u5b9a\u4e86 MySQL \u7684\u4e00\u4e9b\u4ea4\u4e92\u5de5\u5177\uff08MySQL\u547d\u4ee4\u884c\u5ba2\u6237\u7aef\uff09\u7528\u6765\u663e\u793a\u5b57\u7b26\u7684\u4e2a\u6570\u3002<\/p>\n<p>\u6574\u6570\u7c7b\u578b\u6709\u53ef\u9009\u7684<strong>UNSIGNED \u5c5e\u6027<\/strong>\uff0c\u5b83\u8868\u793a\u4e0d\u5141\u8bb8\u8d1f\u503c\uff0c\u8fd9\u5927\u7ea6\u80fd\u4f7f\u6b63\u6574\u6570\u7684\u4e0a\u9650\u63d0\u9ad8\u4e00\u500d\u3002\u4f8b\u5982 TINYINT UNSIGNED \u53ef\u4ee5\u5b58\u50a8\u7684\u503c\u8303\u56f4\u662f 0 ~ 255\uff0c\u800c TINYINT \u7684\u503c\u7684\u5b58\u50a8\u8303\u56f4\u662f -128 ~ 127\u3002\u6211\u4eec\u7684ID\u5217\u662f\u4ece0\u5f00\u59cb\u9012\u589e\u7684\uff0c\u6240\u4ee5\u53ef\u4ee5\u9009\u7528\u8fd9\u4e2a\u5c5e\u6027\u3002<\/p>\n<p>\u90a3\u4e48\uff0c\u6211\u4eec\u5e94\u8be5\u5bf9<code>id<\/code>\u5217\u7684\u5b9a\u4e49\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre><code>`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '\u4e3b\u952e'\n\n\n<\/code><\/pre>\n<p><code>message<\/code>\u5217\u4fdd\u5b58\u7684\u662f\u63a5\u53e3\u4ea4\u4e92\u62a5\u6587\u5185\u5bb9\uff0c\u5b9a\u4e49\u7684\u7c7b\u578b\u662f TEXT\uff0c\u5b83\u8fd8\u6709\u4e00\u4e9b\u76f8\u5173\u7684\u7c7b\u578b\uff0c\u5177\u4f53\u5982\u4e0b\uff08L\u4ee3\u8868\u5b57\u7b26\u4e32\u7684\u5b57\u8282\u957f\u5ea6\uff0c\u6570\u5b57\u8868\u793a\u5b58\u50a8\u5b57\u7b26\u4e32\u5b57\u8282\u957f\u5ea6\u7684\u5b57\u8282\u6570\uff09\uff1a<\/p>\n<p><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000044133206\" alt=\"\" title=\"\"><\/p>\n<p>\u82e5\u62a5\u6587\u5185\u5bb9\u4e2d\u6bcf\u4e2a\u5b57\u7b26\u53ea\u5360\u75281\u5b57\u8282\u7684\u8bdd\uff0c\u90a3\u4e48 TEXT \u7c7b\u578b\u80fd\u6700\u591a\u5b58\u50a8\u5927\u7ea6 65535 \u4e2a\u5b57\u7b26\uff0c\u800c\u5b9e\u9645\u4e0a\u62a5\u6587\u5185\u5bb9\u8fdc\u8fdc\u8fbe\u4e0d\u5230\u8fd9\u4e2a\u957f\u5ea6\uff0c\u800c\u4e14 TEXT \u7c7b\u578b\u662f\u4e3a\u4e86\u5b58\u50a8\u5f88\u5927\u7684\u6570\u636e\u800c\u8bbe\u8ba1\u7684\u5b57\u7b26\u4e32\u6570\u636e\u7c7b\u578b\u3002<\/p>\n<p>\u6211\u4eec\u53ef\u4ee5\u5c06\u5176\u8c03\u6574\u6210 VARCHAR \u7c7b\u578b\uff0c\u5e76\u6839\u636e\u5b9e\u9645\u7684\u62a5\u6587\u957f\u5ea6\u90fd\u4e0d\u8d85\u8fc7 1000 \u6765\u6307\u5b9a\u5b83\u7684\u5b57\u7b26\u6570\u4e3a 1000\uff0c\u907f\u514d\u53d1\u751f\u56e0\u62a5\u6587\u957f\u5ea6\u8fc7\u957f\u800c\u65e0\u6cd5\u4fdd\u5b58\u6570\u636e\u7684\u60c5\u51b5\u3002<strong>\u901a\u5e38\u60c5\u51b5\u4e0bMySQL\u4f1a\u5728\u5185\u5bb9\u5206\u914d\u56fa\u5b9a\u5927\u5c0f\u7684\u5185\u5b58\u6765\u4fdd\u5b58\u503c<\/strong>\uff0c\u6211\u4eec\u8fd9\u6837\u505a\u8282\u7701\u4e86\u5b58\u50a8\u7a7a\u95f4\uff0c\u5bf9\u6027\u80fd\u4e5f\u6709\u5e2e\u52a9\u3002<\/p>\n<p><code>message<\/code>\u7684\u66f4\u6539\u540e\u7684\u5b9a\u4e49\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre><code>`message` varchar(1000) DEFAULT NULL COMMENT '\u62a5\u6587\u5185\u5bb9'\n\n\n<\/code><\/pre>\n<p>VARCHAR \u7c7b\u578b\u4e5f\u9700\u8981\u989d\u5916\u4f7f\u7528 1 \u6216 2 \u5b57\u8282\u6765\u8bb0\u5f55\u5b57\u7b26\u4e32\u5b57\u8282\u7684\u957f\u5ea6\uff1a\u5982\u679c\u5217\u7684\u6700\u5927\u957f\u5ea6\u5c0f\u4e8e\u6216\u7b49\u4e8e 255 \u5b57\u8282\uff0c\u5219\u53ea\u4f7f\u7528 1 \u5b57\u8282\u6765\u8868\u793a\uff1b\u5426\u5219\u4f7f\u7528 2 \u5b57\u8282\u6765\u8868\u793a\u3002<\/p>\n<blockquote><p>MySQL \u5b57\u7b26\u4e32\u957f\u5ea6\u5b9a\u4e49\u7684\u4e0d\u662f\u5b57\u8282\u6570\uff0c\u800c\u662f\u5b57\u7b26\u6570\u3002\u50cf UTF-8 \u8fd9\u6837\u590d\u6742\u7684\u5b57\u7b26\u96c6\u53ef\u80fd\u9700\u8981\u591a\u4e2a\u5b57\u8282\u6765\u5b58\u50a8\u4e00\u4e2a\u5b57\u7b26\u3002<\/p><\/blockquote>\n<h4>\u66f4\u5c0f\u7684\u901a\u5e38\u66f4\u597d<\/h4>\n<p>MySQL \u603b\u662f\u4e3a CHAR \u7c7b\u578b\u5206\u914d\u6240\u5b9a\u4e49\u957f\u5ea6\u7684\u7a7a\u95f4\uff0c\u6240\u4ee5\u5b83\u662f\u56fa\u5b9a\u957f\u5ea6\u7684\uff0c\u5b83\u76f8\u6bd4\u4e8e VARCHAR \u5728\u9762\u5bf9\u7ecf\u5e38\u4fee\u6539\u7684\u6570\u636e\u65f6\u8868\u73b0\u66f4\u597d\uff0c\u56e0\u4e3a\u56fa\u5b9a\u957f\u5ea6\u7684\u5217\u4e0d\u5bb9\u6613\u51fa\u73b0\u5185\u5b58\u788e\u7247\uff0c\u800c\u4e14\u5bf9\u4e8e CHAR(1) \u8fd9\u79cd\u975e\u5e38\u77ed\u7684\u5217\uff0c\u5b83\u8981\u6bd4 VARCHAR(1) \u66f4\u9ad8\u6548\uff0c\u56e0\u4e3a\u524d\u8005\u53ea\u5360\u7528 1 \u4e2a\u5b57\u8282\u7684\u7a7a\u95f4\uff0c\u540e\u8005\u5360\u7528 2 \u4e2a\u5b57\u8282\uff08\u5176\u4e2d 1 \u5b57\u8282\u8bb0\u5f55\u957f\u5ea6\uff09\u3002<\/p>\n<p>CHAR \u7c7b\u578b\u9002\u5408\u5b58\u50a8\u975e\u5e38\u77ed\u7684\u5b57\u7b26\u4e32\u6216\u8005\u6240\u6709\u503c\u957f\u5ea6\u90fd\u51e0\u4e4e\u76f8\u540c\u7684\u5b57\u7b26\u4e32\uff0c\u4e0d\u8fc7\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0cMySQL \u4f1a\u5c06\u6240\u6709<strong>\u5c3e\u968f\u7684\u7a7a\u683c\u79fb\u9664<\/strong>\u3002<\/p>\n<p><code>service_method<\/code>\u5b57\u6bb5\u5b9e\u9645\u4e0a\u4fdd\u5b58\u7684\u662f\u63a5\u53e3\u534f\u8bae\uff0c\u65e0\u975e\u662f HTTP \u548c TCP \u8fd9\u4e24\u79cd\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u5176\u5b9a\u4e49\u4fee\u6539\u4e3a\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre><code>`service_method` char(4) DEFAULT NULL COMMENT '\u63a5\u53e3\u65b9\u5f0f'\n\n\n<\/code><\/pre>\n<p>\u4f46\u662f\u5b9e\u9645\u4e0a\uff0c<strong>\u6574\u578b\u6570\u636e\u6bd4\u5b57\u7b26\u6570\u636e\u7684\u6bd4\u8f83\u64cd\u4f5c\u4ee3\u4ef7\u66f4\u4f4e<\/strong>\uff0c\u5982\u679c\u5728\u5141\u8bb8\u6539\u53d8\u5b57\u6bb5\u7c7b\u578b\u7684\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u5c06\u5176\u4fee\u6539\u4e3a TINYINT \u7c7b\u578b\uff0c\u901a\u8fc7\u5b9a\u4e49\u679a\u4e3e\u503c\u6765\u8868\u793a\u4e0d\u540c\u7684\u534f\u8bae\u6548\u7387\u4f1a\u66f4\u9ad8\u3002<\/p>\n<pre><code>`service_method` tinyint DEFAULT NULL COMMENT '\u63a5\u53e3\u65b9\u5f0f 1-HTTP 2-TCP'\n\n\n<\/code><\/pre>\n<p><code>service_caller<\/code>\u548c<code>service_receiver<\/code>\u5b57\u6bb5\u4e5f\u662f\u4e00\u6837\u7684\u9053\u7406\uff0c\u8fd9\u4e9b\u503c\u90fd\u662f\u56fa\u5b9a\u7684\u679a\u4e3e\uff0c\u6700\u521d\u5e94\u8be5\u4e5f\u5b9a\u4e49\u6210 TINYINT \u7684\u5f62\u5f0f\uff0c\u5982\u4e0b<\/p>\n<pre><code>`service_caller` tinyint DEFAULT NULL COMMENT '\u8c03\u7528\u65b9',\n`service_receiver` tinyint DEFAULT NULL COMMENT '\u63a5\u6536\u65b9'\n\n\n<\/code><\/pre>\n<p><code>service_type<\/code>\u5b57\u6bb5\u4e2d\u5b58\u50a8\u7684\u662f\u5bf9\u5e94\u63a5\u53e3\u7684\u7f16\u7801\u503c\uff0c\u5b83\u4eec\u90fd\u662f\u5bbd\u5ea6\u4e3a 4 \u7684\u6574\u578b\u6570\u636e\uff0c\u6700\u5927\u503c\u4e0d\u4f1a\u8d85\u8fc7 9999\uff0c\u6240\u4ee5\u6839\u636e\u5b83\u7684\u53d6\u503c\u8303\u56f4\u5c06\u5176\u4fee\u6539\u4e3a SMALLINT \u7c7b\u578b\u4f1a\u66f4\u5408\u9002\uff0c\u5982\u4e0b<\/p>\n<pre><code>`service_type` smallint DEFAULT NULL COMMENT '\u63a5\u53e3\u7c7b\u578b'\n\n\n<\/code><\/pre>\n<p><code>service_name<\/code>\u5b57\u6bb5\u63a5\u53e3\u540d\u79f0\u6700\u957f\u4e5f\u4e0d\u4f1a\u8d85\u8fc715\u4e2a\u5b57\u7b26\uff0c\u6240\u4ee5\u6211\u4eec\u5c06\u5b83\u7684 VARCHAR \u5b9a\u4e49\u5b57\u7b26\u957f\u5ea6\u4fee\u6539\u4e00\u4e0b\uff1a<\/p>\n<pre><code>`service_name` varchar(15) DEFAULT NULL COMMENT '\u63a5\u53e3\u540d\u79f0'\n\n\n<\/code><\/pre>\n<p><code>status<\/code>\u5b57\u6bb5\u53ea\u6709 10 \u548c 20 \u4e24\u79cd\u503c\uff0c\u76f8\u6bd4\u4e8e INT\uff0c\u4f7f\u7528 TINYINT \u66f4\u5408\u9002\u4e00\u4e9b<\/p>\n<pre><code>`status` tinyint DEFAULT 10 COMMENT '\u72b6\u6001 10-\u6210\u529f 20-\u5f02\u5e38'\n\n\n<\/code><\/pre>\n<h4>DATETIME \u548c TIMESTAMP<\/h4>\n<p>\u8fd9\u4e24\u79cd\u7c7b\u578b\u975e\u5e38\u76f8\u4f3c\uff0c\u5bf9\u4e8e\u5927\u591a\u6570\u7cfb\u7edf\u6765\u8bf4\uff0c\u8fd9\u4e24\u79cd\u7c7b\u578b\u90fd\u53ef\u4ee5\uff0c\u4e0d\u8fc7\u5b83\u4eec\u4e5f\u6709\u6240\u4e0d\u540c\u3002<\/p>\n<p>DATETIME \u53ef\u4ee5\u4fdd\u5b58\u7684\u65e5\u671f\u8303\u56f4\u66f4\u5927\uff0c\u4ece 1000 \u5e74\u5230 9999 \u5e74\uff0c\u7cbe\u5ea6\u4e3a 1 \u5fae\u79d2\uff0c\u975e\u5c0f\u6570\u90e8\u5206 \u5360\u7528 5 \u4e2a\u5b57\u8282\u7684\u5b58\u50a8\u7a7a\u95f4\uff0c\u5c0f\u6570\u90e8\u5206\u6839\u636e\u7cbe\u5ea6\u5927\u5c0f\u5360\u7528 0 ~ 3 \u4e2a\u5b57\u8282\uff0c\u5e76\u4e14\u5b83<strong>\u4e0e\u65f6\u533a\u65e0\u5173<\/strong>\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0cMySQL \u4ee5 yyyy-MM-dd HH:mm:ss \u7684\u683c\u5f0f\u663e\u793a\u65f6\u95f4\uff0c\u5982\u679c\u9700\u8981\u6307\u5b9a\u7cbe\u5ea6\uff0c\u53ef\u4ee5\u4ee5<code>datetime(6)<\/code>\u7684\u5f62\u5f0f\u5b9a\u4e49\u3002<\/p>\n<p>TIMESTAMP \u7c7b\u578b\u5b58\u50a8\u7684\u662f\u81ea 1970 \u5e74 1 \u6708 1 \u65e5\u683c\u6797\u5c3c\u6cbb\u6807\u51c6\u65f6\u95f4\u4ee5\u6765\u7684\u79d2\u6570\uff08\u7cbe\u5ea6\u4e5f\u4e3a 1 \u5fae\u79d2\uff09\uff0c\u975e\u5c0f\u6570\u90e8\u5206\u5360\u7528 4 \u4e2a\u5b57\u8282\u7684\u5b58\u50a8\u7a7a\u95f4\uff0c\u5c0f\u6570\u90e8\u5206\u4e0e DATETIME \u7c7b\u578b\u5360\u7528\u7a7a\u95f4\u89c4\u5219\u4e00\u81f4\uff0c\u6240\u4ee5\u5b83\u7684\u53d6\u503c\u8303\u56f4\u76f8\u6bd4\u4e8e DATETIME \u8981\u5c0f\uff0c\u53ea\u80fd\u8868\u793a\u4ece 1970 \u5e74\u5230 2038 \u5e74 1 \u6708 19 \u65e5\u7684\u65f6\u95f4\u8303\u56f4\u3002\u800c\u4e14\u8be5\u7c7b\u578b\u4e0eMySQL\u670d\u52a1\u6307\u5b9a\u7684<strong>\u65f6\u533a\u76f8\u5173<\/strong>\uff0c\u8fd9\u5c31\u4f7f\u5f97\u5728\u67e5\u8be2\u65e5\u671f\u65f6\uff0c\u4f1a\u5c06\u65f6\u95f4\u6233\u8f6c\u6362\u4e3a\u6240\u5728\u65f6\u533a\u7684\u65f6\u95f4\u540e\u518d\u663e\u793a\uff0c\u6240\u4ee5\u4e0d\u540c\u5730\u533a\u770b\u5230\u7684\u540c\u4e00\u65f6\u95f4\u6233\u7684\u5b9e\u9645\u65f6\u95f4\u5c55\u793a\u662f\u4e0d\u4e00\u6837\u7684\u3002<\/p>\n<blockquote><p>MySQL \u53ef\u4ee5\u4f7f\u7528 FROM\/_UNIXTIME() \u51fd\u6570\u5c06 UNIX \u65f6\u95f4\u6233\u8f6c\u6362\u6210\u65e5\u671f\uff0c\u4f7f\u7528 UNIX\/_TIMESTAMP() \u51fd\u6570\u5c06\u65e5\u671f\u8f6c\u6362\u4e3a UNIX \u65f6\u95f4\u6233\u3002<\/p><\/blockquote>\n<p>\u4f7f\u7528 DATETIME \u7c7b\u578b\u8fd8\u662f\u4f7f\u7528 TIMESTAMP \u7c7b\u578b\u9700\u8981\u8003\u8651\u4ee5\u4e0b\u95ee\u9898\uff1a<\/p>\n<ul>\n<li>\u5b58\u50a8\u7a7a\u95f4\u5bf9\u6211\u4eec\u6765\u8bf4\u91cd\u8981\u5417\uff1f<\/li>\n<li>\u9700\u8981\u652f\u6301\u524d\u540e\u591a\u5927\u65f6\u95f4\u8303\u56f4\u7684\u65e5\u671f\u548c\u65f6\u95f4\uff1f<\/li>\n<li>\u4fdd\u5b58\u7684\u65e5\u671f\u6570\u636e\u6709\u7cbe\u5ea6\u8981\u6c42\u5417\uff1f<\/li>\n<li>\u662f\u5728MySQL\u4e2d\u5904\u7406\u65f6\u533a\u8fd8\u662f\u5728\u4ee3\u7801\u4e2d\u5904\u7406\u65f6\u533a\uff1f<\/li>\n<\/ul>\n<p>\u62ff\u6211\u4eec\u7684\u5e94\u7528\u6765\u8bf4\uff0cDATETIME \u7c7b\u578b\u4f1a\u66f4\u5408\u9002\u4e00\u4e9b\uff1a<\/p>\n<pre><code>`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '\u521b\u5efa\u65f6\u95f4',\n`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '\u66f4\u65b0\u65f6\u95f4',\n`ts` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '\u65f6\u95f4\u6233'\n\n\n<\/code><\/pre>\n<blockquote><p>\u5982\u679c\u60f3\u8981\u5bf9\u65f6\u95f4\u6233\u8fdb\u884c\u8bb0\u5f55\uff0c\u53ef\u4ee5\u8003\u8651\u4f7f\u7528 BIGINT \u7c7b\u578b\uff0c\u5b83\u4e0d\u4f1a\u9047\u5230 2038 \u5e74\u7684\u95ee\u9898\u3002<\/p><\/blockquote>\n<h4>\u907f\u514d\u4f7f\u7528 NULL<\/h4>\n<p>\u901a\u5e38\u60c5\u51b5\u4e0b\uff0c\u6700\u597d\u6307\u5b9a\u5217\u4e3a NOT NULL\uff0c\u9664\u975e\u660e\u786e\u7684\u9700\u8981\u5b58\u50a8\u4e3a NULL \u503c\u3002\u53ef\u4e3a NULL \u7684\u5217\u4f1a\u4f7f\u7528\u66f4\u591a\u7684\u5b58\u50a8\u7a7a\u95f4\uff0c\u5728 MySQL \u4e2d\u9700\u8981\u7279\u6b8a\u7684\u5904\u7406\uff1b\u67e5\u8be2\u4e2d\u5305\u542b\u53ef\u4e3a NULL \u7684\u5217\u5bf9 MySQL \u6765\u8bf4\u66f4\u96be\u4f18\u5316\uff0c\u56e0\u4e3a\u53ef\u4e3a NULL \u7684\u5217\u4f7f\u5f97\u7d22\u5f15\u3001\u7d22\u5f15\u7edf\u8ba1\u548c\u503c\u7684\u6bd4\u8f83\u66f4\u4e3a\u590d\u6742\u3002<\/p>\n<blockquote>\n<p>MySQL \u9ed8\u8ba4\u7684\u884c\u683c\u5f0f\u4e3a DYNAMIC\uff0c\u5b83\u4f1a\u5728\u6bcf\u884c\u6570\u636e\u4e2d\u8bb0\u5f55\u989d\u5916\u4fe1\u606f\uff0c\u5176\u4e2d\u5c31\u5305\u62ec\u5bf9 NULL \u503c\u5217\u8868\u7684\u8bb0\u5f55\uff0c\u5982\u679c\u6211\u4eec\u6240\u6709\u7684\u5217\u90fd\u4e3a NOT NULL \u7684\u8bdd\uff0c\u90a3\u4e48\u8fd9\u90e8\u5206\u989d\u5916\u4fe1\u606f\u662f\u4e0d\u9700\u8981\u8bb0\u5f55\u7684\u3002<\/p>\n<p>\u4e86\u89e3\uff1aCOMPRESSED \u884c\u683c\u5f0f\u4e0e DYNAMIC \u4e0d\u540c\u7684\u662f\uff0c\u5b83\u4f1a\u5bf9\u5b58\u50a8\u6570\u636e\u7684\u9875\u8fdb\u884c\u538b\u7f29\u4ee5\u8282\u7701\u7a7a\u95f4\uff1bCOMPACT \u884c\u683c\u5f0f\u4e0e DYNAMIC \u548c COMPRESSED \u4e0d\u540c\u7684\u662f\u5728\u5bf9\u6ea2\u51fa\u5217\u7684\u5904\u7406\u4e0a\uff0cCOMPACT \u4f1a\u5b58\u50a8\u6ea2\u51fa\u5217\u7684\u90e8\u5206\u6570\u636e\uff0c\u5269\u4f59\u7684\u6570\u636e\u4f7f\u7528\u5176\u4ed6\u6570\u636e\u9875\u4fdd\u5b58\uff0c\u5e76\u8bb0\u5f55\u4e0b\u4fdd\u5b58\u8fd9\u4e9b\u6570\u636e\u9875\u7684\u6307\u9488\uff0cDYNAMIC \u548c COMPRESSED \u5219\u662f\u5c06\u8be5\u5217\u6240\u6709\u6570\u636e\u90fd\u4fdd\u5b58\u5728\u5176\u4ed6\u6570\u636e\u9875\u4e2d\uff0c\u5728\u8be5\u5217\u6570\u636e\u5904\u53ea\u4fdd\u5b58\u5bf9\u5e94\u6ea2\u51fa\u9875\u7684\u5730\u5740\u3002<\/p>\n<p><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000044133207\" alt=\"COMPACT\u884c\u683c\u5f0f\u793a\u610f\u56fe.png\" title=\"COMPACT\u884c\u683c\u5f0f\u793a\u610f\u56fe.png\" loading=\"lazy\"><\/p>\n<\/blockquote>\n<p>\u4f46\u662f\u5b9e\u9645\u4e0a\u5c06\u5217\u7684\u5b9a\u4e49\u4fee\u6539\u4e3a NOT NULL \u5e26\u6765\u7684\u6027\u80fd\u63d0\u5347\u5e76\u4e0d\u660e\u663e\uff0c\u6240\u4ee5\u5e76\u4e0d\u4f1a\u5c06\u8fd9\u79cd\u4f18\u5316\u4f5c\u4e3a\u9996\u9009\uff0c\u800c\u662f\u5728\u8868\u7ed3\u6784\u521d\u59cb\u5316\u65f6\u8003\u8651\u5230\u8fd9\u4e00\u70b9\u3002<\/p>\n<p>\u4fee\u6539\u597d\uff0c\u6700\u7ec8\u521d\u59cb\u5316\u8868\u7ed3\u6784\u7684 DDL \u8bed\u53e5\u5982\u4e0b\uff1a<\/p>\n<pre><code>CREATE TABLE `service_log` (\n  `id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '\u4e3b\u952e',\n  `service_type` smallint NOT NULL DEFAULT -1 COMMENT '\u63a5\u53e3\u7c7b\u578b',\n  `service_name` varchar(30) DEFAULT '' COMMENT '\u63a5\u53e3\u540d\u79f0',\n  `service_method` tinyint NOT NULL DEFAULT -1 COMMENT '\u63a5\u53e3\u65b9\u5f0f 1-HTTP 2-TCP',\n  `serial_no` int DEFAULT -1 COMMENT '\u6d88\u606f\u5e8f\u53f7',\n  `service_caller` tinyint DEFAULT -1 COMMENT '\u8c03\u7528\u65b9',\n  `service_receiver` tinyint DEFAULT -1 COMMENT '\u63a5\u6536\u65b9',\n  `status` tinyint DEFAULT 10 COMMENT '\u72b6\u6001 10-\u6210\u529f 20-\u5f02\u5e38',\n  `error_message` varchar(200) DEFAULT '' COMMENT '\u5f02\u5e38\u4fe1\u606f',\n  `message` varchar(1000) DEFAULT '' COMMENT '\u62a5\u6587\u5185\u5bb9',\n  `create_user` varchar(50) DEFAULT '' COMMENT '\u521b\u5efa\u8005',\n  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '\u521b\u5efa\u65f6\u95f4',\n  `update_user` varchar(50) DEFAULT '' COMMENT '\u66f4\u65b0\u8005',\n  `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '\u66f4\u65b0\u65f6\u95f4',\n  `is_delete` tinyint NOT NULL DEFAULT 0 COMMENT '\u522a\u9664\u6807\u5fd7',\n  `ts` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '\u65f6\u95f4\u6233',\n  PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='\u63a5\u53e3\u8c03\u7528\u65e5\u5fd7';\n\n\n<\/code><\/pre>\n<h4>TINYINT \u8868\u793a Boolean \u7c7b\u578b<\/h4>\n<p>\u9700\u8981\u6ce8\u610f\uff0cBoolean \u7c7b\u578b\u7684\u503c\u5728 MySQL \u4e2d\u662f\u901a\u8fc7 TINYINT \u6765\u6620\u5c04\u7684\uff0c\u5982\u679c\u5728\u6570\u636e\u5e93\u4e2d\u8be5\u503c\u4e3a 0\uff0c\u90a3\u4e48\u6620\u5c04\u5230 Java \u5bf9\u8c61\u4e2d\u4e3a False\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<p><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000044133208\" alt=\"tyint.png\" title=\"tyint.png\" loading=\"lazy\"><\/p>\n<hr>\n<h4>\u5b9e\u6570\u7c7b\u578b<\/h4>\n<p>\u5b9e\u6570\u7c7b\u578b\u56e0\u4e3a\u5728\u8be5\u8868\u7ed3\u6784\u4e2d\u4f7f\u7528\u4e0d\u5230\u6211\u4eec\u6ca1\u6709\u4ecb\u7ecd\uff0c\u6240\u4ee5\u5728\u8fd9\u91cc\u8fdb\u884c\u8865\u5145\u3002<\/p>\n<p>MySQL \u65e2\u652f\u6301<strong>\u7cbe\u786e\u8ba1\u7b97<\/strong>\u7684\u7c7b\u578b\uff08DECIMAL\uff09\uff0c\u4e5f\u652f\u6301<strong>\u8fd1\u4f3c\u8ba1\u7b97<\/strong>\u7684\u6d6e\u70b9\u7c7b\u578b\uff08FLOAT \u548c DOUBLE\uff09\u3002<\/p>\n<p>FLOAT \u4f7f\u7528 4 \u4e2a\u5b57\u8282\u7684\u5b58\u50a8\u7a7a\u95f4\uff0cDOUBLE \u4f7f\u7528 8 \u4e2a\u5b57\u8282\u7684\u5b58\u50a8\u7a7a\u95f4\uff0c\u53ef\u4ee5\u6307\u5b9a\u5217\u7684\u7cbe\u5ea6\uff0c\u4f46\u662f\u901a\u5e38\u60c5\u51b5\u4e0b\u5efa\u8bae<strong>\u53ea\u6307\u5b9a\u6570\u636e\u7c7b\u578b\uff0c\u800c\u4e0d\u6307\u5b9a\u7cbe\u5ea6<\/strong>\uff0c\u5426\u5219 MySQL \u4f1a\u6839\u636e\u7cbe\u5ea6\u81ea\u884c\u8fdb\u884c\u820d\u5165\uff0c\u800c\u4e14\u5b83\u4eec\u8fd8\u4f1a\u53d7\u5230\u5e73\u53f0\u6216\u5b9e\u73b0\u4f9d\u8d56\u6027\u7684\u5f71\u54cd\u3002<\/p>\n<p>\u6211\u4eec\u770b\u4e0b\u8fb9\u8fd9\u4e2a\u4f8b\u5b50\uff1a<\/p>\n<pre><code>CREATE TABLE `real_number` (\n  `f1` float(7, 4) NOT NULL,\n  `f2` float NOT NULL,\n  `d1` double(7, 4) NOT NULL,\n  `d2` double NOT NULL\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='\u5b9e\u6570';\n\n# \u63d2\u5165\u6570\u636e\nINSERT into real_number values (\n    3.1415926535,\n    3.1415926535,\n    3.1415926535,\n    3.1415926535\n);\n\n# \u67e5\u8be2\u7ed3\u679c\nselect * from real_number;\n\n\n<\/code><\/pre>\n<table>\n<thead>\n<tr>\n<th>f1<\/th>\n<th>f2<\/th>\n<th>d1<\/th>\n<th>d2<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>3.1416<\/td>\n<td>3.14159<\/td>\n<td>3.1416<\/td>\n<td>3.1415926535<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u6839\u636e\u7ed3\u679c\u503c\u6211\u4eec\u53ef\u4ee5\u53d1\u73b0\uff0c\u6307\u5b9a\u4e86\u7cbe\u5ea6\u7684\u6d6e\u70b9\u7c7b\u578b\u8fdb\u884c\u4e86\u820d\u5165\uff0c\u6ca1\u6709\u6307\u5b9a\u7cbe\u5ea6\u7684 FLOAT \u7c7b\u578b\u9ed8\u8ba4\u4fdd\u7559\u4e86\u5c0f\u6570\u70b9\u540e 5 \u4f4d\u5c0f\u6570\uff0c\u81ea\u884c\u7684\u820d\u5165\u53ef\u80fd\u4f1a\u5f15\u8d77\u6df7\u6dc6\u3002<\/p>\n<p>\u901a\u5e38\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u4e3a\u4e86\u4fdd\u8bc1\u6700\u5927\u9650\u5ea6\u7684\u5b9e\u73b0<strong>\u53ef\u79fb\u690d\u6027<\/strong>\uff0c\u9700\u8981\u5b58\u50a8\u8fd1\u4f3c\u6570\u5b57\u6570\u636e\u503c\u7684\u4ee3\u7801\u5e94\u8be5\u4f7f\u7528 FLOAT \u6216 DOUBLE\uff0c\u800c\u4e0d\u6307\u5b9a\u7cbe\u5ea6\u6216\u4f4d\u6570\u3002<\/p>\n<p>\u8fd8\u6709\u4e00\u79cd\u60c5\u51b5\u9700\u8981\u6ce8\u610f\uff0c\u5982\u679c\u6211\u4eec\u8981\u63d2\u5165\u8d85\u8fc7\u6307\u5b9a\u7cbe\u5ea6\u7684\u6574\u6570\u8303\u56f4\uff0c\u4f1a\u5bfc\u81f4\u6570\u636e\u5165\u5e93\u5931\u8d25\uff0c\u5982\u4e0b\uff1a<\/p>\n<pre><code># \u6307\u5b9a f1 \u5217\u6574\u6570\u5bbd\u5ea6\u4e3a 4\uff0c\u5b9e\u9645\u5b9a\u4e49\u5141\u8bb8\u7684\u6700\u5927\u5bbd\u5ea6\u4e3a 3\nINSERT into real_number values (\n3210.1415926535,\n3.1415926535,\n3.1415926535,\n3.1415926535\n);\n\n# \u7ed3\u679c\nSQL \u9519\u8bef [1264] [22001]: Data truncation: Out of range value for column 'f1' at row 1\n\n\n<\/code><\/pre>\n<p>\u5982\u679c\u6ca1\u6709\u6307\u5b9a\u7cbe\u5ea6\u8303\u56f4\uff0c\u90a3\u4e48\u5219\u4f1a\u5bf9\u5c0f\u6570\u90e8\u5206\u8fdb\u884c\u538b\u7f29\uff0c\u7cbe\u5ea6\u53d8\u5c0f\uff0c\u800c\u4e0d\u662f\u63d0\u793a\u5165\u5e93\u5931\u8d25\uff0c\u5982\u4e0b\uff1a<\/p>\n<pre><code># f2 \u5217\u63d2\u5165\u8be5\u503c\uff0c\u67e5\u770b\u7ed3\u679c\nINSERT into real_number values (\n3.1415926535,\n3210.1415926535,\n3.1415926535,\n3.1415926535\n);\n\n\n<\/code><\/pre>\n<table>\n<thead>\n<tr>\n<th>f1<\/th>\n<th>f2<\/th>\n<th>d1<\/th>\n<th>d2<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>3.1416<\/td>\n<td>3210.14<\/td>\n<td>3.1416<\/td>\n<td>3.1415926535<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>DECIMAL \u4e0e FLOAT \u548c DOUBLE \u4e0d\u540c\uff0c\u5728\u8fdb\u884c\u7cbe\u786e\u7684\u5c0f\u6570\u8ba1\u7b97\u65f6\uff0c<strong>\u9700\u8981\u6307\u5b9a\u5b83\u7684\u7cbe\u5ea6<\/strong>\uff0c\u5426\u5219\u9ed8\u8ba4\u60c5\u51b5\u4e0b\u4e3a<code>DECIMAL(10, 0)<\/code>\uff0c\u53ea\u4fdd\u5b58\u6574\u6570\u3002\u800c\u4e14\u5b83\u5728\u5b58\u50a8\u76f8\u540c\u8303\u56f4\u7684\u503c\u662f\u4f1a\u5360\u7528\u66f4\u591a\u7684\u7a7a\u95f4\uff0c\u6240\u4ee5\u51fa\u4e8e\u5bf9\u989d\u5916\u7684\u7a7a\u95f4\u9700\u6c42\u548c\u8ba1\u7b97\u6210\u672c\u7684\u8003\u8651\uff0c\u6211\u4eec\u53ea\u5728\u9700\u8981\u5bf9\u5c0f\u6570\u8fdb\u884c\u7cbe\u786e\u8ba1\u7b97\u65f6\u624d\u4f7f\u7528\u8be5\u7c7b\u578b\u3002<\/p>\n<p>DECIMAL \u7684\u6700\u5927\u4f4d\u6570\u4e3a 65\uff0c\u800c\u4e14\u5f53\u4e3a DECIMAL \u5217\u6307\u5b9a\u7684\u503c\u5c0f\u6570\u70b9\u540e\u4f4d\u6570\u8d85\u8fc7\u5c0f\u6570\u4f4d\u6570\u7cbe\u5ea6\u8303\u56f4\u65f6\uff0c\u8be5\u503c\u5c06\u820d\u5165\u4e3a\u7cbe\u5ea6\u8303\u56f4\u3002\u540c\u6837\u5730\uff0c\u5982\u679c\u6574\u6570\u90e8\u5206\u7684\u5bbd\u5ea6\u5927\u4e8e\u6307\u5b9a\u7684\u7cbe\u5ea6\u8303\u56f4\uff0c\u90a3\u4e48\u4e5f\u4f1a\u53d1\u751f\u8d85\u51fa\u5217\u8303\u56f4\u7684\u5f02\u5e38\u800c\u5bfc\u81f4\u65e0\u6cd5\u6b63\u5e38\u5165\u5e93\uff0c\u5982\u4e0b\uff1a<\/p>\n<pre><code>create table `decimal_t` (\n  `d1` decimal(7, 4) NOT NULL\n)ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='DECIMAL';\n\nINSERT INTO decimal_t values (3.1415926535);\n\n# \u7ed3\u679c\u503c\u4e3a 3.1416\n\nINSERT INTO decimal_t values (1234.1415926535);\n\n# Data truncation: Out of range value for column 'd1' at row 1\n\n\n<\/code><\/pre>\n<p>\u9664\u6b64\u4e4b\u5916\uff0c\u5728\u4e00\u4e9b\u5927\u5bb9\u91cf\u7684\u573a\u666f\u4e0b\uff0c\u53ef\u4ee5\u8003\u8651\u4f7f\u7528 BIGINT \u4ee3\u66ff DECIMAL\uff0c\u5728\u5b58\u50a8\u65f6\u6839\u636e\u5c0f\u6570\u7684\u4f4d\u6570\u4e58\u4ee5\u76f8\u5e94\u7684\u500d\u6570\u5373\u53ef\u3002\u8fd9\u6837\u5c31\u53ef\u4ee5\u540c\u65f6\u907f\u514d\u6d6e\u70b9\u6570\u8ba1\u7b97\u4e0d\u7cbe\u786e\u3001 DECIMAL \u7cbe\u786e\u8ba1\u7b97\u4ee3\u4ef7\u9ad8\u548c\u6570\u503c\u7cbe\u5ea6\u8303\u56f4\u9650\u5236\u7684\u95ee\u9898\u3002<\/p>\n<hr>\n<h4>\u5de8\u4eba\u7684\u80a9\u8180<\/h4>\n<ul>\n<li>\u300a\u9ad8\u6027\u80fd MySQL \u7b2c\u56db\u7248\u300b\uff1a\u7b2c\u516d\u7ae0<\/li>\n<li><a target=\"_blank\" href=\"https:\/\/link.segmentfault.com\/?enc=HyrUuxA70Ck%2FBzO0kzDi0Q%3D%3D.Cb9FmEe7DcDUHtjfr3sMBBuPadDCxWOs6rOmYfc7Ut0ov%2BsfYNOBathLXLhJjAowKSM5JQDuWub4ZllIhjXC5NIXbWUrLyuzXdRL1F6Z5SM%3D\" rel=\"noopener noreferrer\">11.7\u00a0Data Type Storage Requirements<\/a><\/li>\n<li><a target=\"_blank\" href=\"https:\/\/link.segmentfault.com\/?enc=DBGkN4B%2FkKCJDe%2B%2BqpePdA%3D%3D.EC1Zn0Yju77L1Qv%2B9h%2BBEfyzOF%2BDIPEmTFpDUNy0%2BgNEaPlRXMqRgcXh2h0A1YEiTz7liBq1LKvrSazWWt02jg%3D%3D\" rel=\"noopener noreferrer\">mysql\u7684\u65e5\u671f\u65f6\u95f4\u7c7b\u578b\u53ca\u7cbe\u5ea6\u95ee\u9898<\/a><\/li>\n<li><a target=\"_blank\" href=\"https:\/\/link.segmentfault.com\/?enc=9rxW4JZN0JVkrttURTWu3A%3D%3D.xpdMmkQar%2BwUKTHtXlLpeDyizUlbjeO6FK2MWMlaSFvxTpOPD9enmfmIZHwOCVOZ\" rel=\"noopener noreferrer\">MySQL\u4e4bDATETIME\u4e0eTIMESTAMP\u7684\u65f6\u95f4\u7cbe\u5ea6\u95ee\u9898<\/a><\/li>\n<li><a target=\"_blank\" href=\"https:\/\/link.segmentfault.com\/?enc=m4%2FpVK9a86Cq6oeIpOuYJw%3D%3D.jBacgQwtHFkr2mvizIvr3lFmI6yZzrgmHV3jBR8lvdzTAvYfNn0eOAJbjv118FgBevCDJkIcFKfEfFLcG1JLfQ%3D%3D\" rel=\"noopener noreferrer\">11.8\u00a0Choosing the Right Type for a Column<\/a><\/li>\n<li><a target=\"_blank\" href=\"https:\/\/link.segmentfault.com\/?enc=l1z2Rt0dwWblws2e%2BCZXfA%3D%3D.r4qjYBin8sL9HjwpZEMVWCKMb6B73xFk6TSfb4I84len54dz1CnP8dGaI2PKoU38eIzbn4ec5TjqNakUpwYGbpr2zf9%2FY4geW%2FO3WvRDCZo%3D\" rel=\"noopener noreferrer\">11.1.4\u00a0Floating-Point Types (Approximate Value) &#8211; FLOAT, DOUBLE<\/a><\/li>\n<li><a target=\"_blank\" href=\"https:\/\/link.segmentfault.com\/?enc=nY91%2FTvxrv9D%2B1z9Gxcn1Q%3D%3D.36qciy5%2BlB5xQGp3dcN1z6Zdv2%2FbYV2InZLFDRB6aEmv8emz%2Fuz96lHLs8eoXkvRxl0EIXXzsBgRdfdMLv7FoQPfT8i7QMOB7XGiKAsAGfY%3D\" rel=\"noopener noreferrer\">B.3.4.8\u00a0Problems with Floating-Point Values<\/a><\/li>\n<li>\u300aMySQL \u662f\u600e\u6837\u8fd0\u884c\u7684\u300b\uff1a\u7b2c\u56db\u7ae0<\/li>\n<\/ul>\n<blockquote>\n<p>\u4f5c\u8005\uff1a\u4eac\u4e1c\u7269\u6d41 \u738b\u5955\u9f99<\/p>\n<p>\u6765\u6e90\uff1a\u4eac\u4e1c\u4e91\u5f00\u53d1\u8005\u793e\u533a \u81ea\u733f\u5176\u8bf4Tech \u8f6c\u8f7d\u8bf7\u6ce8\u660e\u6765\u6e90<\/p>\n<\/blockquote>\n<p><a href=\"https:\/\/segmentfault.com\/a\/1190000044133204\">https:\/\/segmentfault.com\/a\/1190000044133204<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6700\u8fd1\u56e0\u9700\u6c42\u6539\u52a8\u65b0\u589e\u4e86\u4e00\u4e9b\u6570\u636e\u5e93\u8868\uff0c\u4f46\u662f\u5728\u5b9a\u4e49\u8868\u7ed3\u6784\u65f6\uff0c\u5177\u4f53\u5217\u5c5e\u6027\u7684\u9009\u62e9\u6709\u4e9b\u4e0d\u77e5\u5176\u6240\u4ee5\u7136\uff0c\u7d22\u5f15\u7684\u6dfb\u52a0\u4e5f\u6709\u9057\u6f0f\u548c\u4e0d [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-10008126","post","type-post","status-publish","format-standard","hentry","category-share"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10008126","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10008126"}],"version-history":[{"count":0,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10008126\/revisions"}],"wp:attachment":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10008126"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10008126"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10008126"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}