简体   繁体   中英

MYSQL (Percona) Failed to read auto-increment value from storage engine

I am getting a "Failed to read auto-increment value from storage engine" error from MySQL (Percona), after trying to:

 LOAD DATA LOCAL INFILE

I have been trying to find an answer on stackoverflow and google, but the answers did not solve the problem/error for my case.

The following shows Auto_increment as 1:

show table status like 'my_table_name';

Setting the auto increment value to the next value or to 1 did not solve it:

ALTER TABLE `my_table_name`  AUTO_INCREMENT = 1;

Dropping the auto incrementing id column and recreating it did not solve it.

Dropping the table and recreating it did not solve it.

Dropping the database and recreating it did not solve it.

Destroying all data and rebuilding my docker development environment did not solve it.

Check table extended gave "OK":

 CHECK TABLE distributor_users EXTENDED;

And it is the only auto incrementing value in the table.

This is what I use to create the table:

 CREATE TABLE `my_table_name` (
    `id` int(11) NOT NULL AUTO_INCREMENT,
    `x0` varchar(191) DEFAULT NULL,
    `x1` varchar(4) DEFAULT NULL,
    `x2` varchar(191) DEFAULT NULL,
    `x3` varchar(191) DEFAULT NULL,
    `x4` varchar(191) DEFAULT NULL,
    `x5` varchar(191) DEFAULT NULL,
    `x6` DATE DEFAULT NULL,
    `x7` int(10) DEFAULT NULL,
   PRIMARY KEY (`id`),
   UNIQUE KEY `x0` (`x0`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;

What could it be? Any lead to start looking at is highly welcomed!

I solved it myself by adding to my query:

 SET id = NULL

The new query now looks like this:

 LOAD DATA LOCAL INFILE '$csv_file_location' INTO TABLE $destination_table
 FIELDS TERMINATED BY ','
 ENCLOSED BY '\"'
 IGNORE 1 LINES
 (x0,x1,x2,x3,x4,x5,x6,x7)
 SET id = NULL;

Although my query worked previously without it.

MySQL was trying to place the first column in the csv file into the first column of the database. Setting the column that has the auto_increment to NULL solved it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM