snippetsqlMajor
How can I reset a mysql table auto-increment to 1 in phpMyAdmin?
Viewed 0 times
canincrementautophpmyadminmysqlhowresettable
Problem
I know that in MySQL at the command line I can reset a table's auto-increment field to 1 with this:
I am curious if there is a way to do this from within phpMyAdmin. Something like a check box to reset the auto-increment or something else along those lines?
Not that there is anything wrong with the command line approach. More one of those curiosity things I keep thinking on... Thanks in advance!
ALTER TABLE tablename AUTO_INCREMENT = 1I am curious if there is a way to do this from within phpMyAdmin. Something like a check box to reset the auto-increment or something else along those lines?
Not that there is anything wrong with the command line approach. More one of those curiosity things I keep thinking on... Thanks in advance!
Solution
phpmyadmin
Perhaps you could just select the phpMyAdmin Operations tab:
Since this one of the most frequently asked questions for phpmyadmin, you can learn more about this in this blog : http://trebleclick.blogspot.com/2009/01/mysql-set-auto-increment-in-phpmyadmin.html
Supplemental Info
For an empty table, another way to reset the auto_increment attribute is to run
Don't run this if you have data in it. If you want to hose the data, then be my guest.
In phpmyadmin, just click the
For a nonempty table, you may want to adjust the auto_increment attribute to the highest existing id in use in case higher entries were deleted.
First, optimize the table
Next, locate the highest value for the auto_increment column (say it is
Suppose the answer returns 27. Goto the Operations tab and enter 28.
Perhaps you could just select the phpMyAdmin Operations tab:
- In phpMyAdmin, click on the table you want to reset or change the AUTO_INCREMENT value
- Click on the Operations Tab
- In the Table Options box find the auto_increment field.
- Enter the new auto_increment starting value
- Click on the Go button for the Table Options box.
Since this one of the most frequently asked questions for phpmyadmin, you can learn more about this in this blog : http://trebleclick.blogspot.com/2009/01/mysql-set-auto-increment-in-phpmyadmin.html
Supplemental Info
For an empty table, another way to reset the auto_increment attribute is to run
TRUNCATE TABLE mydb.tablename;Don't run this if you have data in it. If you want to hose the data, then be my guest.
In phpmyadmin, just click the
SQL tab, enter the command, and run it.For a nonempty table, you may want to adjust the auto_increment attribute to the highest existing id in use in case higher entries were deleted.
First, optimize the table
OPTIMIZE TABLE mydb.mytable;Next, locate the highest value for the auto_increment column (say it is
id)SELECT MAX(id) maxid FROM mydb.mytable;Suppose the answer returns 27. Goto the Operations tab and enter 28.
Code Snippets
TRUNCATE TABLE mydb.tablename;OPTIMIZE TABLE mydb.mytable;SELECT MAX(id) maxid FROM mydb.mytable;Context
StackExchange Database Administrators Q#43812, answer score: 23
Revisions (0)
No revisions yet.