有人可以向我解释一下吗?
mysql> select * from heartbeat order by id desc limit 20;
+---------+---------------------+---------------------------------------------------------+
| id | date | node |
+---------+---------------------+---------------------------------------------------------+
| 1944993 | 2013-03-22 12:06:29 | CN=kurian2,O=Nemesis Clinics Group,DC=nemesis,DC=com |
| 1944992 | 2013-03-22 12:05:59 | CN=kurian2,O=Nemesis Clinics Group,DC=nemesis,DC=com |
| 1944991 | 2013-03-22 12:05:29 | CN=kurian2,O=Nemesis Clinics Group,DC=nemesis,DC=com |
| 1944990 | 2013-03-22 12:05:07 | CN=kurian2,O=Nemesis Clinics Group,DC=nemesis,DC=com |
| 1944989 | 2013-03-22 12:05:07 | CN=kurian2,O=Nemesis Clinics Group,DC=nemesis,DC=com |
| 1944988 | 2013-03-22 12:05:07 | CN=kurian2,O=Nemesis Clinics Group,DC=nemesis,DC=com |
| 1944987 | 2013-03-21 21:12:59 | CN=kurian2,O=Nemesis Clinics Group,DC=nemesis,DC=com |
| 1944986 | 2013-03-21 21:12:29 | CN=kurian2,O=Nemesis Clinics Group,DC=nemesis,DC=com |
| 1944985 | 2013-03-21 21:11:59 | CN=kurian2,O=Nemesis Clinics Group,DC=nemesis,DC=com |
| 1944984 | 2013-03-21 21:11:29 | CN=kurian2,O=Nemesis Clinics Group,DC=nemesis,DC=com |
| 1944983 | 2013-03-21 21:10:59 | CN=kurian2,O=Nemesis Clinics Group,DC=nemesis,DC=com |
| 1944982 | 2013-03-21 21:10:29 | CN=kurian2,O=Nemesis Clinics Group,DC=nemesis,DC=com |
| 1944981 | 2013-03-21 21:09:59 | CN=kurian2,O=Nemesis Clinics Group,DC=nemesis,DC=com |
| 1944980 | 2013-03-21 21:09:29 | CN=kurian2,O=Nemesis Clinics Group,DC=nemesis,DC=com |
| 1944979 | 2013-03-21 21:08:59 | CN=kurian2,O=Nemesis Clinics Group,DC=nemesis,DC=com |
| 1944978 | 2013-03-21 21:08:29 | CN=kurian2,O=Nemesis Clinics Group,DC=nemesis,DC=com |
| 1944977 | 2013-03-21 21:07:59 | CN=kurian2,O=Nemesis Clinics Group,DC=nemesis,DC=com |
| 1944976 | 2013-03-21 21:07:29 | CN=kurian2,O=Nemesis Clinics Group,DC=nemesis,DC=com |
| 1944975 | 2013-03-21 21:06:59 | CN=kurian2,O=Nemesis Clinics Group,DC=nemesis,DC=com |
| 1944974 | 2013-03-21 21:06:29 | CN=kurian2,O=Nemesis Clinics Group,DC=nemesis,DC=com |
+---------+---------------------+---------------------------------------------------------+
20 rows in set (0.01 sec)
尝试插入下一个值..
insert into heartbeat values(1944994, '2013-03-22 12:06:29','CN=kurian2,O=Nemesis Clinics Group,DC=nemesis,DC=com');
ERROR 1062(23000):密钥1的重复条目“1944994”
确保该值不存在..
select * from heartbeat where id=1944994;
Empty set (0.00 sec)
mysql> desc heartbeat;
+-------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+--------------+------+-----+---------+----------------+
| id | bigint(20) | NO | PRI | NULL | auto_increment |
| date | datetime | YES | | NULL | |
| node | varchar(255) | YES | | NULL | |
+-------+--------------+------+-----+---------+----------------+
3 rows in set (0.05 sec)
mysql> SHOW VARIABLES LIKE "%version%";
+-------------------------+-------------------------------+
| Variable_name | Value |
+-------------------------+-------------------------------+
| protocol_version | 10 |
| version | 5.0.51b-community-nt |
| version_comment | MySQL Community Edition (GPL) |
| version_compile_machine | ia32 |
| version_compile_os | Win32 |
+-------------------------+-------------------------------+
5 rows in set (0.00 sec)
有没有人遇到同样的问题?为什么我在1944994年获得例外?
答案 0 :(得分:2)
插入行时不要为该列提供值,因为id
是auto_increment。
所以MySQL自动分配了序列号。你也可以显式地为列分配NULL或0来生成序列号。