我正在尝试将数据从管道分隔文件导入到mysql。创建表工作。但是,当我尝试导入数据时,我收到此错误" ERROR 1467(HY000):无法从存储引擎"中读取自动增量值。 我已在网站上查看可能的错误,但任何答案。下面是我正在使用的脚本。我是MySql的新手。
SELECT 'Changing database..' as '';
use test
SELECT 'Droing table if it exists' as '';
DROP TABLE IF EXISTS table1;
CREATE TABLE IF NOT EXISTS table1
(
id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
infohash VARCHAR(100) NOT NULL,
categories VARCHAR(100) DEFAULT NULL,
info_url VARCHAR(300) NOT NULL,
download_url VARCHAR(300) DEFAULT NULL,
PRIMARY KEY (id)
);
SHOW TABLES;
LOAD DATA INFILE '/usr/Software/sample.txt'
INTO TABLE table1
CHARACTER SET utf8
COLUMNS
TERMINATED BY '|'
LINES
TERMINATED BY '\n'
;
SELECT 'Total rows in table' as '';
select count(*) from table1;
这是我得到的输出。
mysql> source table_creattion.sql
+---------------------+
| |
+---------------------+
| Changing database.. |
+---------------------+
1 row in set (0.00 sec)
Database changed
+---------------------------+
| |
+---------------------------+
| Droing table if it exists |
+---------------------------+
1 row in set (0.00 sec)
Query OK, 0 rows affected, 1 warning (0.00 sec)
Query OK, 0 rows affected (0.01 sec)
+----------------+
| Tables_in_test |
+----------------+
| table1 |
+----------------+
1 row in set (0.00 sec)
ERROR 1467 (HY000): Failed to read auto-increment value from storage engine
+---------------------+
| |
+---------------------+
| Total rows in table |
+---------------------+
1 row in set (0.00 sec)
+----------+
| count(*) |
+----------+
| 0 |
+----------+
1 row in set (0.00 sec)
我不确定为什么会出现这个错误。任何人吗?
答案 0 :(得分:0)
尝试将字段名称添加到insert语句中,如下例所示。 在我看来,在sample.txt上,你不必拥有id列的值。 请分享sample.txt中的一些示例行以获得更好的帮助。
LOAD DATA INFILE '/usr/Software/sample.txt'
INTO TABLE table1
(infohash,categories, info_url, download_url )
CHARACTER SET utf8
COLUMNS
TERMINATED BY '|'
LINES
TERMINATED BY '\n'
;
答案 1 :(得分:0)
auto_increment列增加到其上限18446744073709551615
。
答案 2 :(得分:0)
当用户尝试在uniqe键上插入重复值时,这是一个错误。我的解决方案是,插入一个具有已定义ID(以及其他所需列)的新虚拟记录,然后将其删除。
select max(`ID`) from `table1` into @IDmax;
set @IDmax = @IDmax + 1;
insert into `table1` set `ID` = @IDmax;
delete from `table1` where `ID` = @IDmax;