2

I'm trying to insert a row into my database like I always made.
The query I'm using is the following :

INSERT INTO catbeni (Nome) VALUES ('Televisore')

As you can see, I'm using the simplest way to insert a row into the database. Now, I display my table with an HTML table, and I allow people to remove rows directly from the HTML page. By clicking a button, they execute the following query to remove the row :

DELETE FROM table WHERE id=any_id

The problem is that when I delete each records, so that I've got no record in my table, I get this error trying to insert a new one into my database :

Failed to read auto-increment value from storage engine

I already inserted rows in an empty table, but I've never had this error. Looking for a solution online I found a few questions on Stack Overflow, but none of the solutions worked for me. The solution I found most of the time is executing a query on my table to reset the AUTO_INCREMENT property of my PRIMARY KEY.
This is the query, caught from this question :

ALTER TABLE `table_name`  AUTO_INCREMENT = 1

The only solution that worked for me, is accessing phpMyAdmin and inserting manually a row with any id, but I naturally can't solve my problem following this way.
This is the CREATE TABLE statement used to create my table :

CREATE TABLE `catbeni` (
 `ID` int(11) NOT NULL AUTO_INCREMENT,
 `Nome` varchar(255) NOT NULL,
 PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 ROW_FORMAT=COMPACT


I hope I'm clear!
Captain Obvlious
  • 19,754
  • 5
  • 44
  • 74
DamiToma
  • 921
  • 3
  • 9
  • 27
  • Can you tell us how many inserts/how much data you have in the table at the point when you get this error? – Tim Biegeleisen Jul 02 '17 at 14:08
  • @TimBiegeleisen As I told you in my question, I've got no records at the point when I get this error. – DamiToma Jul 02 '17 at 14:09
  • Please show us the `CREATE TABLE` statement used to create your table `catbeni`. – Tim Biegeleisen Jul 02 '17 at 14:11
  • Can you post the ddl/schema for that table? – Robert Moskal Jul 02 '17 at 14:13
  • @TimBiegeleisen I updated my question. Hope to be clear! – DamiToma Jul 02 '17 at 14:13
  • @RobertMoskal I just updated my question :) – DamiToma Jul 02 '17 at 14:14
  • I've never seen this error, but I might suggest that you do inserts using this: `INSERT INTO catbeni (ID, Nome) VALUES (NULL, 'Televisore')` ... other than this, the workarounds you listed seem to be what is recommended for this problem +1 to your question. – Tim Biegeleisen Jul 02 '17 at 14:15
  • @TimBiegeleisen Thanks! I tried your solution, but the error is still appearing. It just disapper when I specify the ID to insert, but as the name itself says, it should be auto increment! – DamiToma Jul 02 '17 at 14:19
  • Which version on MySQL are you using (be as exact as possible here). Can you also run a repair table and see if that outputs anything interesting, or alternative re-create the table. Also check the startup of MySQL for errors on which you might have to run repairs. – Norbert Jul 02 '17 at 17:41
  • @NorbertvanNobelen I'm using MariaDB 10.1.21. It should be exactly the same, isn't it? I can't run a REPAIR TABLE due to my table's manager and the startup of MySQL is ok (I'm using XAMPP). Did I give you the informations you need? – DamiToma Jul 03 '17 at 14:04
  • REPAIR TABLE is a command in MySQL/MariaDB (and a few others by now). If you login in using the mysql command line, you might be able to run it. (What do you mean by *table manager*? Database engine?). For the rest: Useful info. Did you restart the database instance yet? The auto_increment is managed in memory and a bug (which this certainly is), might disappear in this case on restart. Dropping the table might also be required (bug might be triggered due to an undetected error in table layout) – Norbert Jul 03 '17 at 14:13
  • @Hexadect You had a few other issues on that question before you deleted it. You also can't quote placeholders. You should look at the prepared statements doc for whichever driver you are using. – chris85 Jul 03 '17 at 14:21
  • @NorbertvanNobelen Deleting the table solved the issue. Should I be afraid to get this error again? I can't afford to risk this to happen. – DamiToma Jul 03 '17 at 14:33
  • With this happening once, I would be worried about it happening again. It looks like your table corrupted (based on that the drop helped). Corruption can occur due to a multitude of reasons including hardware and OS, but is actually the most likely on hardware (OS filesystem is used by 100s of millions of servers and people, so bugs causing something like this are found rapidly). I would file a bug (despite not having a stack trace etc) at MariaDB and consider upgrade (however blind that is at this point in time) to the 10.2.6 version. Also consider other hardware (at least disk) – Norbert Jul 03 '17 at 14:38
  • @NorbertvanNobelen Thanks for your help! Have a good day. – DamiToma Jul 03 '17 at 14:41

0 Answers0