nixCraft Linux Forum

nixCraft

Linux / UNIX Tech Support Forum

MySQL auto_increment Reset How To

This is a discussion on MySQL auto_increment Reset How To within the Databases servers forums, part of the Mastering Servers category; I need to reset auto_increment in mysql a scenario, Code: +----+---------+---------------+------+---------------------+------------+ | id | HEADING | BODY | FLAG | ...

Register free or login to your existing account and remove all advertisements.


Go Back   nixCraft Linux Forum > Mastering Servers > Databases servers

Linux answers from nixCraft.


Databases servers Discussions of databases of all types - especially MySQL.

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-18-2009, 05:53 PM
kasimani's Avatar
Senior Member
User
 
Join Date: Jul 2006
Location: India, Delhi
OS: CentOS, RedHat, Fedora, Ubuntu
Posts: 151
Thanks: 3
Thanked 1 Time in 1 Post
Rep Power: 4
kasimani is on a distinguished road
Send a message via Yahoo to kasimani
Default MySQL auto_increment Reset How To

I need to reset auto_increment in mysql a scenario,

Code:
+----+---------+---------------+------+---------------------+------------+
| id | HEADING | BODY          | FLAG | creation_date            | IMAGE      |
+----+---------+---------------+------+---------------------+------------+
|  1 |  asd       |asdasdasdas |    0    | 2009-06-18 15:46:01 | Winter.jpg |
|  2 |  sdf       |ZZxsdsadsas  |    0    | 2009-06-18 15:49:01 | human.jpg |
|  3 | dgdf       |gdfgdf         |    0    | 2009-06-18 15:52:33 | Sunset.jpg |
+----+---------+---------------+------+---------------------+------------+
3 rows in set (0.00 sec)

If i delete the 3 number data, then i can regenerate the auto_increment by issuing this query:

Code:
 ALTER TABLE table_name AUTO_INCREMENT=1

what to do if i delete 2 number data, and after that need to reset auto_increment.

example:

Code:
+----+---------+---------------+------+---------------------+------------+
| id | HEADING | BODY          | FLAG | creation_date            | IMAGE      |
+----+---------+---------------+------+---------------------+------------+
|  1 |  asd       |asdasdasdas |    0    | 2009-06-18 15:46:01 | Winter.jpg |
|  3 | dgdf       |gdfgdf         |    0    | 2009-06-18 15:52:33 | Sunset.jpg |
+----+---------+---------------+------+---------------------+------------+
2 rows in set (0.00 sec)
Pl. it needed very urgently...

Thanks
Regards
Manish Singh

Last edited by nixcraft; 06-20-2009 at 02:22 AM.
Reply With Quote
  #2 (permalink)  
Old 06-20-2009, 02:28 AM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
OS: RHEL
Scripting language: Bash and Python
Posts: 2,672
Thanks: 11
Thanked 240 Times in 180 Posts
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

Try
Code:
SET insert_id = 2;
INSERT INTO  table_name VALUES ('foo','bar');
__________________
Vivek Gite
Linux Evangelist
Be proud RHEL user, and let the world know about your enterprise choices! Join RedHat user group.
Always use CODE tags for posting system output and commands!
Do you run a Linux? Let's face it, you need help
Reply With Quote
  #3 (permalink)  
Old 06-22-2009, 05:02 PM
kasimani's Avatar
Senior Member
User
 
Join Date: Jul 2006
Location: India, Delhi
OS: CentOS, RedHat, Fedora, Ubuntu
Posts: 151
Thanks: 3
Thanked 1 Time in 1 Post
Rep Power: 4
kasimani is on a distinguished road
Send a message via Yahoo to kasimani
Default

[SOLVED]

no no, if these type of missing are in whole table, then ?

suppose i have table of 10k entries, and such missing are there just like in example...

on 2 position 3, 9 , 110, etc...

Last edited by kasimani; 06-23-2009 at 03:07 PM. Reason: [SOLVED]
Reply With Quote
  #4 (permalink)  
Old 06-23-2009, 05:24 AM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
OS: RHEL
Scripting language: Bash and Python
Posts: 2,672
Thanks: 11
Thanked 240 Times in 180 Posts
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

I'm afraid but you need to write a perl or php script to find and automate this.
__________________
Vivek Gite
Linux Evangelist
Be proud RHEL user, and let the world know about your enterprise choices! Join RedHat user group.
Always use CODE tags for posting system output and commands!
Do you run a Linux? Let's face it, you need help
Reply With Quote
Reply

Tags
mysql , mysql change autoincrement value , mysql reset auto increament number


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads

Thread Thread Starter Forum Replies Last Post
[Solved] Reset Router Password / Configuration Malikussaid Networking, Firewalls and Security 7 05-04-2009 05:14 PM
passwd reset pansarevai CentOS / RHEL / Fedora 4 03-24-2008 10:39 PM
Redhat Users vsftpd FTP Passwd Reset Problem bubloob_13 CentOS / RHEL / Fedora 1 11-05-2007 09:03 PM
how to reset root and user passwords - new install forlornhope Linux software 2 07-05-2007 01:51 AM


All times are GMT +5.5. The time now is 01:03 PM.


Powered by vBulletin® Version 3.8.4 - Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2
©2005-2009 nixCraft. All rights reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38