tags:

views:

53

answers:

3

I'm running into a really, really, really weird problem with mysql.

I have a primary key, "id". It's set to auto increment. Problem is, first entry started at "3". And every new entry increases by 5, so the next entry's id is 8, the next is 13, then 18, so on. This is stupid. Why isn't it just incrementing by 1, like it should be? And why is it starting at 3???

Is there some setting somewhere I'm missing? I'm using phpmyadmin, if that helps.

+1  A: 

The auto increment is probably set to 5. Try:

ALTER TABLE YourTable AUTO_INCREMENT = 1;

You can retrieve the current setting with:

SHOW TABLE STATUS LIKE 'YourTable'

See the MySQL docs for more details.

Andomar
Nope... That table setting sets the next value to use. It cannot be lower than or equal to the largest key already in use by the table. It has nothing to do with how many the field is incremented by each time (that's handled by the `auto_increment_increment` variable). The use for what you posted is so that if you wanted to skip a bunch of ids for some reason (like saving room for future expansion)...
ircmaxell
Didn't work, but thanks for showing me "show table status". Nifty.
nwalker85
@ircmaxell: You're right, thanks
Andomar
+1  A: 

it appears the table was created with an increment set to 5. you can change it back to one with the following:

ALTER TABLE tbl AUTO_INCREMENT = 1;
programatique
Didn't work. Thanks though.
nwalker85
+6  A: 

There's a my.cnf configuration for that: auto_increment_increment. It's used for master-master server setups to prevent the same key from being defined twice by two different servers. So using that coupled with auto_increment_offset, it allows each server to always generate unique ids...

So, from what you're describing, it sounds like you have this:

auto_increment_increment = 5
auto_increment_offset = 3
ircmaxell
+1: Beat me to it
OMG Ponies
I'm willing to bet this is the problem. Too bad I don't have access to the my.cnf file. Thanks for pointing me in the right direction. I guess I'm stuck with this... Here's hoping I don't run into any weird problems.
nwalker85
Well, based on http://dev.mysql.com/doc/refman/5.0/en/server-system-variables.html, it's settable as a session variable. So you could call `SET SESSION auto_increment_increment = 1;` at the start of each connection if you REALLY wanted to (but beware that if there is replication going on, you could potentially break things)...
ircmaxell