MySql 字段 int(1) 和 int(10) 有什么区别?
CREATE TABLE `user` ( `id` int(1) unsigned NOT NULL AUTO_INCREMENT, PRIMARY KEY (`id`)) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4;
mysql> INSERT INTO `user` (`id`) VALUES (4294967295);Query OK, 1 row affected (0.00 sec)
CREATE TABLE `user` ( `id` int(4) unsigned zerofill NOT NULL AUTO_INCREMENT, PRIMARY KEY (`id`)) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4;
mysql> INSERT INTO `user` (`id`) VALUES (1),(10),(100),(1000);Query OK, 4 rows affected (0.00 sec)Records: 4 Duplicates: 0 Warnings: 0
mysql> select * from user;+------+| id |+------+| 0001 || 0010 || 0100 || 1000 |+------+4 rows in set (0.00 sec)