3

Using MySQL Workbench, I have a MySQL InnoDB with a few hundred records.

The records table has the following format (id is auto_increment and unique);

+------+-------+
| id   | name  |
+------+-------+
| 2500 | jo    |
+------+-------+
| 2511 | jim   |
+------+-------+
| 2512 | sarah |
+------+-------+
| 2513 | jane  |
+------+-------+

Notice my first record begins at 2500. Presumably this is because I have dropped and re-imported the table data numerous times.

Is there any way I can 'reset' the id field so that the records begin at 1 and not 2500?

I want the table to look like this:

+----+-------+
| id | name  |
+----+-------+
| 1  | jo    |
+----+-------+
| 2  | jim   |
+----+-------+
| 3  | sarah |
+----+-------+
| 4  | jane  |
+----+-------+

Any advice is appreciated.

1

1 Answer 1

3
TRUNCATE TABLE tbl;

If that does not work,

ALTER TABLE tbl AUTO_INCREMENT=1;

But you should not depend on the actual values of AUTO_INCREMENT. There are many things that can make it non-reproducible.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.