phpmyadmin
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.
No, the auto increment functionality of MySQL (or MariaDB) does not provide some kind of "dynamic" auto increment values like you request. The formula you arranged is all MySQL can do.
In your case you might be better of in just abandoning the auto increment column and use a custom column instead. You can fill this for example with UUIDs. This does not guarantee uniqueness of generated IDs, but the possibility to generate the exact same IDs is very low.
Best Answer
No, you can't. Not out of the box. Possible workarounds:
Triggers (an
AFTER INSERT
trigger).Disadvantages:
Advantages:
FOREIGN KEY
constraints that reference this column.Views. If you only a value that is always
+4000400
of the first auto incremented value, you can use a view, so basically not store this value at all, just calculate it when you need it:Disadvantages:
FOREIGN KEY
constraint that references this (virtual) column.Advantages:
Don't do that, don't have a second auto incremented column at all. Do you really need a second auto incremented value? What for? A description of the actual problem you are trying to solve would help others help you better. I think you have only told here how you tried to solve a problem and not what the actual problem is.