向mysql中插入时候总出现这种错误Error: Duplicate entry '1' for key 1
插入语句:
insert into test_data values (null,1,now());CREATE TABLE `test_data` (
`order_id` INT UNSIGNED auto_increment NOT NULL COMMENT 'Order numbers. Must be unique.',
`status` BOOL NOT NULL DEFAULT '0' COMMENT 'Whether data has been used or not. A value of 0 means FALSE.',
`date_used` DATETIME NULL COMMENT 'Date/time that the data was used.',
UNIQUE (
`order_id`
)
) ENGINE = innodb COMMENT = 'LoadRunner test data';
插入语句:
insert into test_data values (null,1,now());CREATE TABLE `test_data` (
`order_id` INT UNSIGNED auto_increment NOT NULL COMMENT 'Order numbers. Must be unique.',
`status` BOOL NOT NULL DEFAULT '0' COMMENT 'Whether data has been used or not. A value of 0 means FALSE.',
`date_used` DATETIME NULL COMMENT 'Date/time that the data was used.',
UNIQUE (
`order_id`
)
) ENGINE = innodb COMMENT = 'LoadRunner test data';
自增字段不能为NULL,可以不用写
这个说法不正确。当某字段为自增时,可以用null, 或者0 代替。楼主的这个insert into test_data values (null,1,now()); 没有问题。仅用你这个表,应该也不会出现你所说的故障。你的表中不是不还有触发器之类的? 或者你程序中有没有这种语句insert into test_data values (1,1,now()); ?
一般在你的MYSQL的数据文件datadir目录中有一个以 err 为扩展名的文本文件,直接用记事本打开或者其它文本编辑器打开。
一般在你的MYSQL的数据文件datadir目录中有一个以 err 为扩展名的文本文件,直接用记事本打开或者其它文本编辑器打开。
+---------------+-----------------------------------------------+
| Variable_name | Value |
+---------------+-----------------------------------------------+
| datadir | C:\Program Files\MySQL\MySQL Server 5.1\DATA\ |
+---------------+-----------------------------------------------+
1 row in set (0.00 sec)mysql>
InnoDB: The error means that another program is using InnoDB's files.
InnoDB: This might be a backup or antivirus software or another instance
InnoDB: of MySQL. Please close it to get rid of this error.但我只是在loadrunner里面测试用了这个数据库的啊,出错也是在在loadrunner测试插入的时候才报这个错。Duplicate entry '1' for key 1
在相同的这个目录中,找一下,有没有以 .log 为扩展名的。
插入语句是:insert into test_data values (1,0,now());order_id不是自增长形式。
而是提交的 insert into test_data values (1,0,now());
而是提交的 insert into test_data values (1,0,now());