Howto reset AUTO_INCREMENT from a table in MySQL/MariaDB Databases

undefined

In this post, I’ll show you how to reset the auto_increment field from a table in MySQL/MariaDB databases. Sometimes you need to drop all the data in an existing table and reset the auto_increment to start from 1.

This post is dealing with only resetting the auto_increment to 1.

To reset the auto_increment, you need to know  the table name you’ll run the following command against. Connect to your database server and select the database that contains the table.

For example. I want to reset the auto_increment  from a table called finance, Run the following command:

ALTER TABLE finance AUTO_INCREMENT = 1;

For InnoDB you cannot set the auto_increment value lower or equal to the highest current index.

Note that you cannot reset the counter to a value less than or equal to any that have already been used. For MyISAM, if the value is less than or equal to the maximum value currently in the AUTO_INCREMENT column, the value is reset to the current maximum plus one. For InnoDB, if the value is less than the current maximum value in the column, no error occurs and the current sequence value is not changed.

I hope this article is good enough for you.

See you in other articles.

If You Appreciate What We Do Here On Mimastech, You Should Consider:

  1. Stay Connected to: Facebook | Twitter | Google+
  2. Support us via PayPal Donation
  3. Subscribe to our email newsletters.
  4. Tell other sysadmins / friends about Us - Share and Like our posts and services

We are thankful for your never ending support.

Leave a Reply

Your email address will not be published. Required fields are marked *