DS9
DS9

Reputation: 3033

Autoincrement id increase by 2

I use following query to create table news:

CREATE TABLE IF NOT EXISTS `news` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `news_title` varchar(500) NOT NULL,
  `news_detail` varchar(5000) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; 

mysql> desc news;
+-------------+---------------+------+-----+---------+----------------+
| Field       | Type          | Null | Key | Default | Extra          |
+-------------+---------------+------+-----+---------+----------------+
| id          | int(11)       | NO   | PRI | NULL    | auto_increment |
| news_title  | varchar(500)  | NO   |     |         |                |
| news_detail | varchar(5000) | NO   |     |         |                |
+-------------+---------------+------+-----+---------+----------------+

mysql> insert into news (news_title, news_detail) values ('test','demod demo');



mysql> select * from news;
+----+--------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------+
| id | news_title                                                               | news_detail                                                                                                        |
+----+--------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------+
|  3 | Advani wants to shift from Gujarat, BJP trying to convince him otherwise | testt |
|  5 | test                                                                     | demod demo                                                                                                         |
+----+--------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------+

as you see in the select query the id is increment like 1,3,5,7.... means it increment by 2. So what is the problem here?

actually in my local, it is increment by 1 and working perfectly. but in my server it creates the problem. Thanks in advance.

Upvotes: 2

Views: 2139

Answers (2)

jmail
jmail

Reputation: 6134

Why ?

The auto_increment value can be change with the variable auto_increment_increment.Normally, it’s always 1, but for some weird reason it was set to 2 in my case. I think MySQL Workbench may be involed.

You can change it be doing one of those :

SET @@auto_increment_increment=1

SET GLOBAL auto_increment_increment=1;

More information

You can find some information here and here.

Upvotes: 2

Elixir Techne
Elixir Techne

Reputation: 1856

Check system variable @@set_auto_increment_increment.

it should be

SET @@auto_increment_increment=1;

Upvotes: 1

Related Questions