测试版本:MySQL 5.5.56
测试类型:int、bigint、float、double、char、varchar
测试结果
长度 | int | bigint | float | double | char | varchar |
0 | 无法定义 | 无法定义 | 14 | 9e99 | null | null |
1 | 3 | 3 | 0 | 0 | 1 | 1 |
2 | 4 | 4 | 0 | 0 | 2 | 2 |
10 | 9 | 12 | 0 | 0 | 10 | 10 |
100 | 9 | 18 | 38 | 71 | 98 | 98 |
255 | 9 | 18 | 38 | 82 | 255 | 255 |
测试结论
(1)数字类型最大支持位数:int 9 位,bigint 18 位,flat 38 位,double 82 位,char 255 位、varchar 255 位
(2)字符串定义的长度即字符个数,但数字类型定义的长度并不代表数字位数
测试数据
/*
Navicat Premium Data Transfer
Source Server : localhost_3306
Source Server Type : MySQL
Source Server Version : 50556
Source Host : localhost:3306
Source Schema : test
Target Server Type : MySQL
Target Server Version : 50556
File Encoding : 65001
Date: 08/03/2020 03:02:09
*/
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
-- ----------------------------
-- Table structure for test
-- ----------------------------
DROP TABLE IF EXISTS `test`;
CREATE TABLE `test` (
`id` int(20) NOT NULL AUTO_INCREMENT,
`int1(1)` int(1) NULL DEFAULT NULL,
`int(2)` int(2) NULL DEFAULT NULL,
`int(10)` int(10) NULL DEFAULT NULL,
`int(100)` int(100) NULL DEFAULT NULL,
`int(255)` int(255) NULL DEFAULT NULL,
`bigint(1)` bigint(1) NULL DEFAULT NULL,
`bigint(2)` bigint(2) NULL DEFAULT NULL,
`bigint(10)` bigint(10) NULL DEFAULT NULL,
`bigint(100)` bigint(100) NULL DEFAULT NULL,
`bigint(255)` bigint(255) NULL DEFAULT NULL,
`float(0)` float NULL DEFAULT NULL,
`float(1)` float(1, 1) NULL DEFAULT NULL,
`float(2)` float(2, 2) NULL DEFAULT NULL,
`float(10)` float(10, 10) NULL DEFAULT NULL,
`float(100)` float(100, 30) NULL DEFAULT NULL,
`float(255)` float(255, 30) NULL DEFAULT NULL,
`double(0)` double NULL DEFAULT NULL,
`double(1)` double(1, 1) NULL DEFAULT NULL,
`double(2)` double(2, 2) NULL DEFAULT NULL,
`double(10)` double(10, 10) NULL DEFAULT NULL,
`double(100)` double(100, 30) NULL DEFAULT NULL,
`double(255)` double(255, 30) NULL DEFAULT NULL,
`varchar(0)` varchar(0) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`varchar(1)` varchar(1) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`varchar(2)` varchar(2) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`varchar10)` varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`varchar100)` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`varchar255)` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`char(0)` char(0) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`char(1)` char(1) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`char(2)` char(2) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`char(10)` char(10) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`char(100)` char(100) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`char(255)` char(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`placeholder` varchar(200) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 3 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
-- ----------------------------
-- Records of test
-- ----------------------------
INSERT INTO `test` VALUES (1, 999, 9999, 999999999, 999999999, 999999999, 999, 9999, 999999999999, 999999999999999999, 999999999999999999, 99999900000000, 0.0, 0.00, 0.0000000000, 99999996802856920000000000000000000000.000000000000000000000000000000, 99999996802856920000000000000000000000.000000000000000000000000000000, 9e99, 0.0, 0.00, 0.0000000000, 10000000000000000000000000000000000000000000000000000000000000000000000.000000000000000000000000000000, 1000000000000000000000000000000000000000000000000000000000000000000000000000000000.000000000000000000000000000000, '', '9', '99', '9999999999', '\r\n99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999', '999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999', '', '9', '99', '9999999999', '\r\n99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999', '99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999991119999999999999999999999', '88888888');
INSERT INTO `test` VALUES (2, 999, 9999, 999999999, 999999999, 999999999, 999, 9999, 999999999999, 999999999999999999, 999999999999999999, 99999900000000, 0.0, 0.00, 0.0000000000, 99999996802856920000000000000000000000.000000000000000000000000000000, 99999996802856920000000000000000000000.000000000000000000000000000000, 9e99, 0.0, 0.00, 0.0000000000, 10000000000000000000000000000000000000000000000000000000000000000000000.000000000000000000000000000000, 1000000000000000000000000000000000000000000000000000000000000000000000000000000000.000000000000000000000000000000, '', '9', '99', '9999999999', '\r\n99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999', '999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999', '', '9', '99', '9999999999', '\r\n99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999', '你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你', '88888888');
SET FOREIGN_KEY_CHECKS = 1;
注意事项:
(1)不同的MySQL版本、不同的数据库引擎和不同的字符编码格式结果会大同小异
(2)这里测试的场景是MySQL5.5.56,InoDB引擎,UFT-8编码,测试结果仅供参考
(3)其他不同版本、数据库引擎和字符编码等不同情况下的差异可以自行测试