国产成人精品18p,天天干成人网,无码专区狠狠躁天天躁,美女脱精光隐私扒开免费观看

MySQL數據庫auto_increment自增值回溯

發(fā)布時(shí)間:2021-09-14 18:07 來(lái)源:億速云 閱讀:0 作者:chen 欄目: Mysql 歡迎投稿:712375056

本篇內容介紹了“數據auto_increment自增值回溯”的有關(guān)知識,在實(shí)際案例的操作過(guò)程中,不少人都會(huì )遇到這樣的困境,接下來(lái)就讓小編帶領(lǐng)大家學(xué)習一下如何處理這些情況吧!希望大家仔細閱讀,能夠學(xué)有所成!

# 創(chuàng )建關(guān)于表t,其中a字段為主鍵自增

mysql> create table t(a bigint primary key auto_increment, b tinyint);

Query OK, 0 rows affected (0.03 sec)

# 插入一些數據

mysql> insert into t select null, 10;

Query OK, 1 row affected (0.00 sec)

Records: 1  Duplicates: 0  Warnings: 0

mysql> insert into t select null, 20;

Query OK, 1 row affected (0.00 sec)

Records: 1  Duplicates: 0  Warnings: 0

mysql> insert into t select null, 30;

Query OK, 1 row affected (0.00 sec)

Records: 1  Duplicates: 0  Warnings: 0

mysql> insert into t select null, 40;

Query OK, 1 row affected (0.00 sec)

Records: 1  Duplicates: 0  Warnings: 0

# 查看表記錄

mysql> select * from t;

+---+------+

| a | b    |

+---+------+

| 1 |   10 |

| 2 |   20 |

| 3 |   30 |

| 4 |   40 |

+---+------+

4 rows in set (0.00 sec)

# 刪除最后一條數據

mysql> delete from t where a=4;

Query OK, 1 row affected (0.02 sec)

# 查看表創(chuàng )建語(yǔ)句,發(fā)現AUTO_INCREMENT=5

mysql> show create table t\G

*************************** 1. row ***************************

       Table: t

Create Table: CREATE TABLE `t` (

  `a` bigint(20) NOT NULL AUTO_INCREMENT,

  `b` tinyint(4) DEFAULT NULL,

  PRIMARY KEY (`a`)

) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1

1 row in set (0.00 sec)

# 進(jìn)行主鍵回溯模擬

# 重啟數據庫

[root@mysql ~]# service mysqld restart

Shutting down MySQL.. SUCCESS!

Starting MySQL. SUCCESS!

# 重新查看表創(chuàng )建語(yǔ)句,發(fā)現AUTO_INCREMENT=4

mysql> show create table t\G

*************************** 1. row ***************************

       Table: t

Create Table: CREATE TABLE `t` (

  `a` bigint(20) NOT NULL AUTO_INCREMENT,

  `b` tinyint(4) DEFAULT NULL,

  PRIMARY KEY (`a`)

) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1

1 row in set (0.00 sec)

# 繼續插入語(yǔ)句

mysql> insert into t select null, 50;

Query OK, 1 row affected (0.00 sec)

Records: 1  Duplicates: 0  Warnings: 0

# 查看表的數據,發(fā)現上述自增ID=4又重新出現

mysql> select * from t;

+---+------+

| a | b    |

+---+------+

| 1 |   10 |

| 2 |   20 |

| 3 |   30 |

| 4 |   50 |

+---+------+

4 rows in set (0.00 sec)

這是因為在MySQL5.7中的表的AUTO_INCREMENT是基于內存,不會(huì )持久化在磁盤(pán)中,每次啟動(dòng)數據庫時(shí),會(huì )對每張表進(jìn)行max(auto_increment) + 1重新作為該表下一次的主鍵ID的自增值。在MySQL8.0中就不會(huì )出現該問(wèn)題,因為數據會(huì )在磁盤(pán)中持久化。

免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng )、來(lái)自本網(wǎng)站內容采集于網(wǎng)絡(luò )互聯(lián)網(wǎng)轉載等其它媒體和分享為主,內容觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如侵犯了原作者的版權,請告知一經(jīng)查實(shí),將立刻刪除涉嫌侵權內容,聯(lián)系我們QQ:712375056,同時(shí)歡迎投稿傳遞力量。

日本japanese超丰满| 99R在线精品视频在线播放| 国产美女牲交视频 | 国产高清在线精品一区| 国产乱人伦AV在线无码| 亚洲精品国产欧美一二区|