无码视频在线观看,99人妻,国产午夜视频,久久久久国产一级毛片高清版新婚

  • 始創(chuàng)于2000年 股票代碼:831685
    咨詢熱線:0371-60135900 注冊有禮 登錄
    • 掛牌上市企業(yè)
    • 60秒人工響應(yīng)
    • 99.99%連通率
    • 7*24h人工
    • 故障100倍補(bǔ)償
    全部產(chǎn)品
    您的位置: 網(wǎng)站首頁 > 幫助中心>文章內(nèi)容

    MySQL中的auto_increment的問題

    發(fā)布時間:  2012/7/30 17:08:35

    發(fā)現(xiàn)一個看似很簡單的MySQL問題,卻引起了大家的廣泛關(guān)注:

    這是一道很早的面試題:

    一張表,里面有ID自增主鍵,當(dāng)insert了17條記錄之后,刪除了第15,16,17條記錄,再把Mysql重啟,再insert一條記錄,這條記錄的ID是18還是15 。

    答案:

    如果表的類型是MyISAM,那么是18。
    因?yàn)镸yISAM表會把自增主鍵的最大ID記錄到數(shù)據(jù)文件里,重啟MySQL自增主鍵的最大ID也不會丟失。
    -
     

    如果表的類型是InnoDB,那么是15。
    InnoDB表只是把自增主鍵的最大ID記錄到內(nèi)存中,所以重啟數(shù)據(jù)庫或者是對表進(jìn)行OPTIMIZE操作,都會導(dǎo)致最大ID丟失。

    自己也做了個實(shí)驗(yàn),結(jié)果證實(shí)了上面的說法。真是慚愧啊,看似簡單的問題自己也打錯了。

    1.mysql> select * from test1; 
    2.+----+-----------+ 
    3.| id | name      | 
    4.+----+-----------+ 
    5.|  1 | 陳兵輝    | 
    6.|  2 | chen      | 
    7.|  3 | chen      | 
    8.|  4 | chen      | 
    9.|  5 | chen      | 
    10.|  6 | chen      | 
    11.|  7 | chen      | 
    12.|  8 | chen      | 
    13.|  9 | chen      | 
    14.| 10 | chen      | 
    15.| 11 | chen      | 
    16.+----+-----------+ 
    17.11 rows in set (0.00 sec) 
    18. 
    19.mysql> delete from test1 where id in (10,11,9); 
    2.Query OK, 3 rows affected (0.03 sec) 
    3. 
    4.mysql> show create table test1;  5. CREATE TABLE `test1` ( 
    6.  `id` int(11) NOT NULL auto_increment, 
    7.  `name` varchar(10) default NULL, 
    8.  PRIMARY KEY  (`id`) 
    9.) ENGINE=InnoDB AUTO_INCREMENT=<span style="color:#ff0000;">12</span> DEFAULT CHARSET=utf8 |  10.mysql> exit;  11.Bye 
    12.[root@fsailing1 ~]# service mysqld restart 
    13.停止 MySQL:                                               [確定] 
    14.啟動 MySQL:                                               [確定] 
    15.[root@fsailing1 ~]# mysql -uroot -p 
    16.Enter password: 
    17.Welcome to the MySQL monitor.  Commands end with ; or \g. 
    18.Your MySQL connection id is 2 
    19.Server version: 5.0.95 Source distribution 
    20.Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. 
    21. 
    22.Oracle is a registered trademark of Oracle Corporation and/or its 
    23.affiliates. Other names may be trademarks of their respective 
    24.owners. 
    25. 
    26.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. 
    27. 
    28.mysql> use test;  29.Reading table information for completion of table and column names 
    30.You can turn off this feature to get a quicker startup with -A 
    31. 
    32.Database changed 
    33.mysql> show create table test1;  34.| CREATE TABLE `test1` ( 
    35.  `id` int(11) NOT NULL auto_increment, 
    36.  `name` varchar(10) default NULL, 
    37.  PRIMARY KEY  (`id`) 
    38.) ENGINE=InnoDB AUTO_INCREMENT=<span style="color:#ff0000;">9</span> DEFAULT CHARSET=utf8 |  2,另外還有一個就是獲取當(dāng)前數(shù)據(jù)庫表的自增字段數(shù)。

    1.mysql> select last_insert_id(); 
    2.+------------------+ 
    3.| last_insert_id() | 
    4.+------------------+ 
    5.|                0 | 
    6.+------------------+ 
    7.1 row in set (0.00 sec) 
     


    本文出自:億恩科技【mszdt.com】

    服務(wù)器租用/服務(wù)器托管中國五強(qiáng)!虛擬主機(jī)域名注冊頂級提供商!15年品質(zhì)保障!--億恩科技[ENKJ.COM]

  • 您可能在找
  • 億恩北京公司:
  • 經(jīng)營性ICP/ISP證:京B2-20150015
  • 億恩鄭州公司:
  • 經(jīng)營性ICP/ISP/IDC證:豫B1.B2-20060070
  • 億恩南昌公司:
  • 經(jīng)營性ICP/ISP證:贛B2-20080012
  • 服務(wù)器/云主機(jī) 24小時售后服務(wù)電話:0371-60135900
  • 虛擬主機(jī)/智能建站 24小時售后服務(wù)電話:0371-60135900
  • 專注服務(wù)器托管17年
    掃掃關(guān)注-微信公眾號
    0371-60135900
    Copyright© 1999-2019 ENKJ All Rights Reserved 億恩科技 版權(quán)所有  地址:鄭州市高新區(qū)翠竹街1號總部企業(yè)基地億恩大廈  法律顧問:河南亞太人律師事務(wù)所郝建鋒、杜慧月律師   京公網(wǎng)安備41019702002023號
      1
     
     
     
     

    0371-60135900
    7*24小時客服服務(wù)熱線