RE: How MyISAM handle auto_increment
-Original Message- From: Lucio Chiappetti [mailto:lu...@lambrate.inaf.it] Sent: Thursday, October 06, 2011 3:18 AM To: Jerry Schwartz Cc: Mysql List Subject: RE: How MyISAM handle auto_increment On Wed, 5 Oct 2011, Jerry Schwartz wrote: Can't you use CREATE TABLE LIKE and then reset the auto-increment value? Thanks. Since when does create table like exist? I was unaware of it, but I see it exists in mysql 5.1. The tricks I described worked since 3.x or thereabouts. [JS] I don't know when it was introduced. I never used anything before 4.0, and I don't remember when I first used it that command. Regards, Jerry Schwartz Global Information Incorporated 195 Farmington Ave. Farmington, CT 06032 860.674.8796 / FAX: 860.674.8341 E-mail: je...@gii.co.jp Web site: www.giiresearch.com -- Lucio Chiappetti - INAF/IASF - via Bassini 15 - I-20133 Milano (Italy) Citizens entrusted of public functions have the duty to accomplish them with discipline and honour [Art. 54 Constitution of the Italian Republic] For more info : http://www.iasf-milano.inaf.it/~lucio/personal.html -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/mysql?unsub=je...@gii.co.jp -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/mysql?unsub=arch...@jab.org
RE: How MyISAM handle auto_increment
On Wed, 5 Oct 2011, Jerry Schwartz wrote: Can't you use CREATE TABLE LIKE and then reset the auto-increment value? Thanks. Since when does create table like exist? I was unaware of it, but I see it exists in mysql 5.1. The tricks I described worked since 3.x or thereabouts. -- Lucio Chiappetti - INAF/IASF - via Bassini 15 - I-20133 Milano (Italy) Citizens entrusted of public functions have the duty to accomplish them with discipline and honour [Art. 54 Constitution of the Italian Republic] For more info : http://www.iasf-milano.inaf.it/~lucio/personal.html -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/mysql?unsub=arch...@jab.org
Re: How MyISAM handle auto_increment
On Mon, 3 Oct 2011, Reindl Harald wrote: I have questions regarding how MyISAM handles auto_increment clolumn? it is a table-property and you hould NOT touch it without godd reasons because it is named AUTO I guess there are quite often good reasons to change it, which can be done e.g. as alter table north33b auto_increment=21; I often generate an empty table with the same structure as another table with a statement like : create table select * from limit 0; (at this point I have to recreate also all indices etc. doing a show create table and show create table and alter table for anything which is missing) The new table will have auto increment starting where ended. This is good (assuming will not grow any more) to preserve an UNIQUE sequence for all tables different for each table. In case one wants to start at a round number one can just issue an alter table and reset auto_increment. The same if one tests some procedure to populate a new table , then deletes everything, and wants that production population restarts from 1. -- Lucio Chiappetti - INAF/IASF - via Bassini 15 - I-20133 Milano (Italy) Citizens entrusted of public functions have the duty to accomplish them with discipline and honour [Art. 54 Constitution of the Italian Republic] For more info : http://www.iasf-milano.inaf.it/~lucio/personal.html -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/mysql?unsub=arch...@jab.org
Re: How MyISAM handle auto_increment
At 04:46 PM 10/3/2011, you wrote: Hi, Folks: I have questions regarding how MyISAM handles auto_increment clolumn? 1. is there a auto_increment counter for MyISAM to assign a new value to auto_increment columns? Yes 2. if MyISAM has the counter, is the counter stored in memory or disk? Thnaks It is stored with the table definition. It is only reset to 0 when the table is (re)created. You can get the last AutoInc for the record that was just added by Select Last_Insert_Id(). See http://dev.mysql.com/doc/refman/5.0/en/example-auto-increment.html Mike -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/mysql?unsub=arch...@jab.org
Re: How MyISAM handle auto_increment
Thanks, what about if mysqld restart, does auto_increment gets reset ? I saw this happened to Innodb, if table is empty and server restart, auto_incremnet gets reset to 0 From: mos mo...@fastmail.fm To: mysql@lists.mysql.com Sent: Monday, October 3, 2011 3:01 PM Subject: Re: How MyISAM handle auto_increment At 04:46 PM 10/3/2011, you wrote: Hi, Folks: I have questions regarding how MyISAM handles auto_increment clolumn? 1. is there a auto_increment counter for MyISAM to assign a new value to auto_increment columns? Yes 2. if MyISAM has the counter, is the counter stored in memory or disk? Thnaks It is stored with the table definition. It is only reset to 0 when the table is (re)created. You can get the last AutoInc for the record that was just added by Select Last_Insert_Id(). See http://dev.mysql.com/doc/refman/5.0/en/example-auto-increment.html Mike -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/mysql?unsub=yyll2...@yahoo.com
Re: How MyISAM handle auto_increment
Am 03.10.2011 23:46, schrieb Angela liu: Hi, Folks: I have questions regarding how MyISAM handles auto_increment clolumn? 1. is there a auto_increment counter for MyISAM to assign a new value to auto_increment columns? 2. if MyISAM has the counter, is the counter stored in memory or disk? it is a table-property and you hould NOT touch it without godd reasons because it is named AUTO signature.asc Description: OpenPGP digital signature
Re: How MyISAM handle auto_increment
At 06:21 PM 10/3/2011, Angela liu wrote: Thanks, what about if mysqld restart, does auto_increment gets reset ? No. The next auto increment value stays with the table. As another person already stated, you should never manually change the auto increment value on a table that already has rows in it. MySQL always handles the incrementing of an AutoInc field. I saw this happened to Innodb, if table is empty and server restart, auto_incremnet gets reset to 0 This shouldn't happen unless MySQL crashes. Perhaps you are confusing the next Auto Increment value with the Last_Insert_Id() (stored in server memory) which has a value only AFTER the user has inserted a row. There can be a hundred connections (each with their own session) adding rows to the same table at the same time. Last_Insert_Id() will retrieve the autoinc value of the record that was just inserted for YOUR session. You won't get someone else's AutoInc value, only the autoinc value for the record that YOU just inserted. So if you insert a record, wait 5 minutes, then execute a Select Last_Insert_Id(), you will get the correct autoinc value that was used when YOUR record was inserted, even though another hundred records were added while you waited to execute the Select statement. You can never really reliably know what the autoinc value will be for the record you are about to insert until AFTER the record has been inserted and you execute Last_Insert_Id() to retrieve this autoinc value. I hope this clears it up. Mike From: mos mo...@fastmail.fm To: mysql@lists.mysql.com Sent: Monday, October 3, 2011 3:01 PM Subject: Re: How MyISAM handle auto_increment At 04:46 PM 10/3/2011, you wrote: Hi, Folks: I have questions regarding how MyISAM handles auto_increment clolumn? 1. is there a auto_increment counter for MyISAM to assign a new value to auto_increment columns? Yes 2. if MyISAM has the counter, is the counter stored in memory or disk? Thnaks It is stored with the table definition. It is only reset to 0 when the table is (re)created. You can get the last AutoInc for the record that was just added by Select Last_Insert_Id(). See http://dev.mysql.com/doc/refman/5.0/en/example-auto-increment.html Mike -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/mysql?unsub=yyll2...@yahoo.com -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/mysql?unsub=arch...@jab.org