Sample Header Ad - 728x90

AUTO_INCREMENT value is incremented by one after a restart of MariaDB

1 vote
2 answers
88 views
I need your help to understand some behaviour of MariaDB/InnoDB. I have a dump file I use to initialize my database. Below is the dump file:
-- MariaDB dump 10.19  Distrib 10.11.5-MariaDB, for Win64 (AMD64)
--
-- Host: localhost    Database: capture_plan016
-- ------------------------------------------------------
-- Server version	10.11.5-MariaDB

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

--
-- Table structure for table _secrol
--

DROP TABLE IF EXISTS _secrol;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE _secrol (
  SECROL_ID bigint(20) NOT NULL AUTO_INCREMENT,
  SECROL_DESC varchar(255) NOT NULL DEFAULT '',
  PRIMARY KEY (SECROL_ID)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table _secrol
--

LOCK TABLES _secrol WRITE;
/*!40000 ALTER TABLE _secrol DISABLE KEYS */;
INSERT INTO _secrol VALUES
(1,'Role 1'),
(2,'Role 2');
/*!40000 ALTER TABLE _secrol ENABLE KEYS */;
UNLOCK TABLES;
As you can see the CREATE TABLE statement specify the AUTO_INCREMENT VALUE. After playing this dump file, I check the AUTO_INCREMENT value and it is, as expected, equal to 3. The strange behaviour (to me) occurs when i restart the MariaDB server (with a normal shutdown). After the restart the AUTO_INCREMENT value is 4. But no INSERT nor DELETE were performed. Well after some manipulations I managed to find a solution to this "problem" (I know it should not be a problem but I want to rely on predictable values only for test purposes). If I use two seperates file (one for the table creation, and one for the inserts) it works fine with a predictible auto increment value. But I would like to understand why the auto_increment value is changed when all the statements takes place in one file. If somebody have some explanation he is welcome =D
Asked by Florian Masy (11 rep)
Aug 20, 2024, 01:54 PM
Last activity: Aug 20, 2024, 06:42 PM