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

    ---

  • 相关阅读:
    Jmeter 接口测试实战-有趣的cookie
    Jmeter输出完美报告
    记忆-走进古镇
    JMeter接口测试实战-动态数据验证
    JMeter写入文件
    正则表达式匹配任意字符(包括换行符)
    No toolchains found in the NDK toolchains folder for ABI with prefix: mips64el-linux-android"
    Unable to get the CMake version located at
    adb 查看 android手机的CPU架构
    java.lang.UnsatisfiedLinkError:dlopen failed: “**/*/arm/*.so” has unexpected e_machine: 3
  • 原文地址:https://www.cnblogs.com/JiangLe/p/11194441.html
Copyright © 2011-2022 走看看