假如表中包含一列为auto_increment,

如果是Myisam类型的引擎,那么在删除了最新一笔数据,无论是否重启Mysql,下一次插入之后仍然会使用上次删除的最大ID+1.

mysql> create table test_myisam (id int not null auto_increment primary key, name char(5)) engine=myisam;

Query OK, 0 rows affected (0.04 sec)

mysql> insert into test_myisam (name) select ‘a‘;

Query OK, 1 row affected (0.00 sec)

Records: 1 Duplicates: 0 Warnings: 0

mysql> insert into test_myisam (name) select ‘b‘;

Query OK, 1 row affected (0.00 sec)

Records: 1 Duplicates: 0 Warnings: 0

mysql> insert into test_myisam (name) select ‘c‘;

Query OK, 1 row affected (0.00 sec)

Records: 1 Duplicates: 0 Warnings: 0

mysql> insert into test_myisam (name) select name from test_myisam;

Query OK, 3 rows affected (0.00 sec)

Records: 3 Duplicates: 0 Warnings: 0

mysql> select * from test_myisam;

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

| id | name |

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

| 1 | a |

| 2 | b |

| 3 | c |

| 4 | a |

| 5 | b |

| 6 | c |

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

6 rows in set (0.00 sec)

mysql> delete from test_myisam where id=6;

Query OK, 1 row affected (0.00 sec)

mysql> insert into test_myisam(name) select ‘d‘;

Query OK, 1 row affected (0.00 sec)

Records: 1 Duplicates: 0 Warnings: 0

mysql> select * from test_myisam;

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

| id | name |

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

| 1 | a |

| 2 | b |

| 3 | c |

| 4 | a |

| 5 | b |

| 7 | d |

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

6 rows in set (0.00 sec)

下面是对Innodb表的测试。

mysql> create table test_innodb(id int not null auto_increment primary key, name char(5)) engine=innodb;

Query OK, 0 rows affected (0.26 sec)

mysql> insert into test_innodb (name)select ‘a‘;

Query OK, 1 row affected (0.06 sec)

Records: 1 Duplicates: 0 Warnings: 0

mysql> insert into test_innodb (name)select ‘b‘;

Query OK, 1 row affected (0.06 sec)

Records: 1 Duplicates: 0 Warnings: 0

mysql> insert into test_innodb (name)select ‘c‘;

Query OK, 1 row affected (0.07 sec)

Records: 1 Duplicates: 0 Warnings: 0

mysql> select * from test_innodb;

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

| id | name |

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

| 1 | a |

| 2 | b |

| 3 | c |

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

3 rows in set (0.00 sec)

mysql> delete from test_innodb where id=3;

Query OK, 1 row affected (0.05 sec)

mysql> insert into test_innodb (name)select ‘d‘;

Query OK, 1 row affected (0.20 sec)

Records: 1 Duplicates: 0 Warnings: 0

mysql> select * from test_innodb;

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

| id | name |

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

| 1 | a |

| 2 | b |

| 4 | d |

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

3 rows in set (0.00 sec)

mysql> exit

Bye

[2@a data]$ mysql -uroot -pwsdad

Welcome to the MySQL monitor. Commands end with ; or g.

Your MySQL connection id is 5

Server version: 5.5.37-log Source distribution

Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

Type ‘help;‘ or ‘h‘ for help. Type ‘c‘ to clear the current input statement.

mysql> use wison

Database changed

mysql> delete from test_innodb where id=4;

Query OK, 1 row affected (0.07 sec)

mysql> exit

Bye

[2@a data]$ sudo service mysql restart

Shutting down MySQL... SUCCESS!

Starting MySQL.. SUCCESS!

[2@a data]$ mysql -uroot -pwison

Welcome to the MySQL monitor. Commands end with ; or g.

Your MySQL connection id is 1

Server version: 5.5.37-log Source distribution

Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

Type ‘help;‘ or ‘h‘ for help. Type ‘c‘ to clear the current input statement.

mysql> use wison

Database changed

mysql> insert into test_innodb (name) select ‘z‘;

Query OK, 1 row affected (0.07 sec)

Records: 1 Duplicates: 0 Warnings: 0

mysql> select * from test_innodb;

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

| id | name |

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

| 1 | a |

| 2 | b |

| 3 | z |

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

3 rows in set (0.00 sec)

可以看到在mysql数据库没有重启时,innodb的表新插入数据会是之前被删除的数据再加1.

但是当Mysql服务被重启后,再向InnodB的自增表表里插入数据,那么会使用当前Innodb表里的最大的自增列再加1.

原因:

Myisam类型存储引擎的表将最大的ID值是记录到数据文件中,不管是否重启最大的ID值都不会丢失。但是InnoDB表的最大的ID值是存在内存中的,若不重启Mysql服务,新加入数据会使用内存中最大的数据+1.但是重启之后,会使用当前表中最大的值再+1

感谢阅读此文,希望能帮助到大家,谢谢大家对本站的支持!

mysql 复制表结构和数据实例代码

在mysql数据库开发中,我们有时候需要复制或拷贝一张表结构和数据到例外一张表,这个时候我们可以使用create...select...from语句来实现,本文章向大家

mysql中key 、primary key 、unique key 与index区别

mysql中索引是非常重要的知识点,相比其他的知识点,索引更难掌握,并且mysql中的索引种类也有很多,比如primarykey、uniquekey与index等等,本文章向大家

mysql alter table命令修改表结构实例

mysql实例之使用altertable命令修改表结构mysqlaltertable语句可以修改表的基本结构,例如添加字段、删除字段、添加主键、添加索引、修改字段数据类型、

mysql的identity_Mysql中Identity 详细介绍相关推荐

  1. HTML中Css详细介绍

    HTML中Css详细介绍 一.样式表的作用 1.Css样式表,层叠样式表 2.类似于人类的衣服,网页的衣服 3.作用:美化网页 4.优势: 1.内容与表现分离,便于维护 2.样式丰富,页面布局灵活 3 ...

  2. java中Cookie详细介绍

    Cookie是由服务器端生成,发送给User-Agent(一般是浏览器),浏览器会将Cookie的key/value保存到某个目录下的文本文件内,下次请求同一网站时就发送该Cookie给服务器(前提是 ...

  3. php mysql explain_Mysql分析-explain的详细介绍

    为什么要了解explain: 想了解select查询的内部情况,查询优化器是如何工作的,是否使用到了索引,explain可以做到. MySQL查询优化器是如何工作的 : MySQL查询优化器有几个目标 ...

  4. Canal Mysql binlog 同步至 ElasticSearch 详细介绍

    文章目录 数据同步ElasticSearch 单表基本配置 适配器映射文件详细介绍(单表.多表映射介绍) 单表映射索引示例sql 单表映射索引示例sql带函数或运算操作 多表映射(一对一, 多对一)索 ...

  5. python如何使用多线程_python多线程应用中的详细介绍

    python多线程在应用的时候有不少的事情需要重点的注意.其实只要掌握这些相关的技术段就能保证这个应用的完整.下面我们来看看具体是需要如何进行操作. 今天看了近一天关于多线程的应用中,如何安全调用py ...

  6. MySQL断开SpringBoot_如何使用SpringBoot解决Mysql断连问题的详细介绍

    本篇文章主要介绍了Spring Boot如何解决Mysql断连问题,小编觉得挺不错的,现在分享给大家,也给大家做个参考.一起跟随小编过来看看吧 在Spring Boot JPA连接Mysql的过程中, ...

  7. mysql innodb 锁类型_详细介绍MySQL InnoDB存储引擎各种不同类型的锁

    本文中,我们详细介绍MySQLInnoDB存储引擎各种不同类型的锁,以及不同SQL语句分别会加什么样的锁. 阅读提示 1.本文所参考的MySQL文档版本是8.0,做实验的MySQL版本是8.0.13 ...

  8. Mysql Binlog三种格式详细介绍

    binlog 的不同模式有什么区别呢? 1.Statement:每一条会修改数据的sql都会记录在binlog中. 优点:不需要记录每一行的变化,减少了binlog日志量,节约了IO,提高性能.(相比 ...

  9. 【MySQL基础教程】事务详细介绍

    前言 本文为 [MySQL基础教程]事务 相关知识,下边将对事务简介,事务操作(包括:未控制事务,控制事务),事务四大特性,并发事务问题,事务隔离级别等进行详尽介绍~

  10. mysql qc_MySQL里QC的详细介绍

    你了解Query Cache多少?如果这些都还不清楚的话,就有必要从它的原理开始说起了,下面就跟随爱站技术频道小编来看一看吧! 原理 QueryCache(下面简称QC)是根据SQL语句来cache的 ...

最新文章

  1. JS 退出系统并跳转到登录界面的实现代码
  2. JBOSS的管理员账号和密码设定
  3. 写文件+三剑客+别名
  4. hibernate 与 spring 松散配置的问题
  5. 前端学习(1359) :学生档案信息管理1
  6. Dev Express Report 学习总结(五)在分组中使用聚集表达式AggregateExpression
  7. DataGridView控件的使用 1206 半草稿
  8. QNX Hardware connection
  9. 服务器ibmc无法加载js文件,引入网络js
  10. NO.128 开发团队篇:参加项目计划会议,分解任务,领取任务,每天更新任务。...
  11. 将运算放大器(运放)用作比较器
  12. 各种泵的图形符号_液压泵以及液压马达的常见图形符号
  13. CUDA+OpenCV 绘制朱利亚(Julia)集合图形
  14. hermit插值 matlab,埃尔米特(Hermite)插值及其MATLAB程序
  15. C# 上位机倒数计时器
  16. linux如何添加360网站卫士ip,使用加速乐、360网站卫士PHP无法获取用户IP的解决方法...
  17. luogu P3084 [USACO13OPEN]照片Photo
  18. 最专业的职业生涯规划测试集合(推荐)
  19. 为什么软件测试工程师跳槽,越跳越值钱。嘎嘎涨薪
  20. 灯箱效果lightbox.js的使用示例

热门文章

  1. caffe 6中优化方法并附带 对应的solver。prototxt代码
  2. MacBook 安装win7双系统、2013款MacBook air安装双系统教程
  3. 找准盈利模式,博客网站赚钱也轻松
  4. 如何用手机访问电脑本地localhost网页, 以调试项目
  5. linux中文件权限为d-rwxr-xr,Linux基础知识之文件权限详解
  6. SpringMVC入门运行成功的实例(一)
  7. 别人家的阿里巴巴校招
  8. 解除百度云下载限制速度(谷歌浏览器)
  9. 讯飞离线语音合成(语记)
  10. 页面提示“百度未授权使用地图API,可能是因为您提供的密钥不是有效的百度LBS开放平台密钥,或此密钥未对本应用的百度地图JavaScriptAPI授权。您可以访问如下网址了解如何获取有效的密钥:ht”