zoukankan      html  css  js  c++  java
  • MySQL-8.0.x DDL 原子性

    1、mysql-8.0.x 新特性之 DDL 原子性

    在没有 DDL 原子性之前 DBA 对 DDL 语句基本上是无能为力的,比如说 DDL 执行的过程中停电了,这下就只有天知道了。实现上最终的愿景还是希望得到一个确定的结果,要么成功了,要么失败了。mysql-8.0.x 带来了 DDL 原子性

    2、mysql-5.6.x DDL 操作的表现

    mysql-5.6.x 并不保证原子性,所以当我们一次 drop 多个表的时候就有可能遇到部分成功的情况

    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 还是被删除了
            

    3、mysql-8.0.x DDL 操作原子性

    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 表还在。

    4、mysql-5.7.x 也表现出了 DDL 原子性的支持

    之所以说 5.7 是看起来像是支持 DDL 原子性,是因为在官方文档上并没有提到它支持,但是它表现了一些与 8.0 类似的行为能力。

    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/52

    ---

  • 相关阅读:
    svn command line tag
    MDbg.exe(.NET Framework 命令行调试程序)
    Microsoft Web Deployment Tool
    sql server CI
    VS 2010 One Click Deployment Issue “Application Validation did not succeed. Unable to continue”
    mshtml
    大厂程序员站错队被架空,只拿着五折工资!苟活和离职,如何选择?
    揭秘!Windows 为什么会蓝屏?微软程序员竟说是这个原因...
    喂!千万别忘了这个C语言知识!(~0 == -1 问题)
    Linux 比 Windows 更好,谁反对?我有13个赞成理由
  • 原文地址:https://www.cnblogs.com/JiangLe/p/11194441.html
Copyright © 2011-2022 走看看