【一、mysql-8.0.x 新特性之 DDL 原子性】mysql
在没有 DDL 原子性以前 DBA 对 DDL 语句基本上是无能为力的,好比说 DDL 执行的过程当中停电了,这下就只有天知道了。实现上最终的愿景仍是但愿获得一个肯定的结果,要么成功了,要么失败了。mysql-8.0.x 带来了 DDL 原子性sql
【二、mysql-5.6.x DDL 操做的表现】spa
mysql-5.6.x 并不保证原子性,因此当咱们一次 drop 多个表的时候就有可能遇到部分红功的状况code
mysql> select @@version; +-----------+ | @@version | +-----------+ | 5.6.44 | +-----------+ 1 row in set (0.00 sec) -- mysql-5.6.44 mysql> show tables; +------------------+ | Tables_in_tempdb | +------------------+ | t | +------------------+ 1 row in set (0.00 sec) -- 库中只有一个表 t mysql> drop table t,t_not_exists; ERROR 1051 (42S02): Unknown table 'tempdb.t_not_exists' -- 尝试一次删除多张表 t & t_not_exists mysql> show tables; Empty set (0.00 sec) -- 虽然 t_not_exists 表并不存在,可是 t 仍是被删除了
【三、mysql-8.0.x DDL 操做原子性】blog
mysql-8.0.x 提供了原子性支持,保证了 DDL 操做要么所有成功、要么所有失败。文档
mysql> select @@version; +-----------+ | @@version | +-----------+ | 8.0.16 | +-----------+ 1 row in set (0.00 sec) mysql> show tables; +------------------+ | Tables_in_tempdb | +------------------+ | t | +------------------+ 1 row in set (0.00 sec) mysql> drop table t ,t_not_exists; ERROR 1051 (42S02): Unknown table 'tempdb.t_not_exists' mysql> show tables; +------------------+ | Tables_in_tempdb | +------------------+ | t | +------------------+ 1 row in set (0.00 sec) -- 由于对 t_not_exists 的操做失败了,因此整个 DDL 都回滚了;这也就解释了为何 t 表还在。
【四、mysql-5.7.x 也表现出了 DDL 原子性的支持】get
之因此说 5.7 是看起来像是支持 DDL 原子性,是由于在官方文档上并无提到它支持,可是它表现了一些与 8.0 相似的行为能力。io
mysql> select @@version; +------------+ | @@version | +------------+ | 5.7.26-log | +------------+ 1 row in set (0.00 sec) mysql> show tables; +------------------+ | Tables_in_tempdb | +------------------+ | t | +------------------+ 1 row in set (0.00 sec) mysql> drop table t ,t_not_exists; ERROR 1051 (42S02): Unknown table 'tempdb.t,tempdb.t_not_exists' -- 二者在错误信息上仍是有必定的差异 -- 8.0 会报 t_not_exists 表不存在 -- 5.7 会报 t 和 t_not_exists 都不存在 mysql> show tables; +------------------+ | Tables_in_tempdb | +------------------+ | t | +------------------+ 1 row in set (0.00 sec)
引用自:https://www.sqlpy.com/blogs/books/1/chapters/12/articles/52table
---class