当前位置:网站首页>16MySQL之DCL 中 COMMIT和ROllBACK
16MySQL之DCL 中 COMMIT和ROllBACK
2022-04-23 20:17:00 【gh-xiaohe】
文章目录
作者: gh-xiaohe
gh-xiaohe的博客
觉得博主文章写的不错的话,希望大家三连(关注,点赞,评论),多多支持一下!!
DCL 中 COMMIT和ROllBACK
DCL 中 COMMIT和ROllBACK
COMMIT
COMMIT:提交数据。一旦执行COMMIT,则数据就被永久的保存在了数据库中,意味着数据不可以回滚。
ROLLBACK
ROLLBACK:回滚数据。一旦执行ROLLBACK,则可以实现数据的回滚。回滚到最近的一次COMMIT之后。
对比
- 相同点:都可以实现对表中所有数据的删除,同时保留表结构。
- 不同点:
- TRUNCATE TABLE:一旦执行此操作,表数据全部清除。同时,数据是不可以回滚的。
- DELETE FROM:一旦执行此操作,表数据可以全部清除(不带WHERE)。同时,数据是可以实现回滚的。
DDL 和 DML 的说明
① DDL的操作一旦执行,就不可回滚。指令SET autocommit = FALSE对DDL操作失效。(因为在执行完DDL操作之后,一定会执行一次COMMIT。而此COMMIT操作不受SET autocommit = FALSE影响的。)
② DML的操作默认情况,一旦执行,也是不可回滚的。但是,如果在执行DML之前,执行了 SET autocommit = FALSE,则执行的DML操作就可以实现回滚。
案例
COMMIT、DELETE
# 演示:DELETE FROM #1) COMMIT; #2) SELECT * FROM myemp3; #3) SET autocommit = FALSE; #4) DELETE FROM myemp3; #5) SELECT * FROM myemp3; #6) ROLLBACK; #7) SELECT * FROM myemp3;
COMMIT、 ROLLBACK
# 演示:TRUNCATE TABLE #1) COMMIT; #2) SELECT * FROM myemp3; #3) SET autocommit = FALSE; #4) TRUNCATE TABLE myemp3; #5) SELECT * FROM myemp3; #6) ROLLBACK; #7) SELECT * FROM myemp3;
MySQL8.0的新特性:DDL的原子化
在MySQL 8.0版本中,InnoDB表的DDL支持事务完整性,即DDL操作要么成功要么回滚。DDL操作回滚日志写入到data dictionary数据字典表mysql.innodb_ddl_log(该表是隐藏的表,通过show tables无法看到)中,用于回滚操作。通过设置参数,可将DDL操作日志打印输出到MySQL错误日志中。
分别在MySQL 5.7版本和MySQL 8.0版本中创建数据库和数据表,结果如下:
CREATE DATABASE mytest; # 创建数据库 mytest USE mytest; # 切换到 mytest 数据库下 CREATE TABLE book1( # 创建 book1 表 book_id INT , book_name VARCHAR(255) ); SHOW TABLES; # 查看当前数据下的表
(1)在MySQL 5.7版本中,测试步骤如下:
# 在 mysql5.7 下 DROP TABLE book1,book2; # 此时删除数据库 book1 和 book2 注意此时没有 book2 SHOW TABLES;
(2)在MySQL 8.0版本中,测试步骤如下:
# 在 mysql8.0 下 DROP TABLE book1,book2; # 此时删除数据库 book1 和 book2 注意此时没有 book2 SHOW TABLES;
版权声明
本文为[gh-xiaohe]所创,转载请带上原文链接,感谢
https://blog.csdn.net/gh_xiaohe/article/details/124314094
边栏推荐
- Rédaction de thèses 19: différences entre les thèses de conférence et les thèses périodiques
- Markdown < a > tag new page open link
- Is the wechat CICC wealth high-end zone safe? How to open an account for securities
- MySQL advanced lock - overview of MySQL locks and classification of MySQL locks: global lock (data backup), table level lock (table shared read lock, table exclusive write lock, metadata lock and inte
- R语言使用timeROC包计算无竞争风险情况下的生存资料多时间AUC值、使用confint函数计算无竞争风险情况下的生存资料多时间AUC指标的置信区间值
- 使用 WPAD/PAC 和 JScript在win11中进行远程代码执行
- Intersection calculation of straight line and plane in PCL point cloud processing (53)
- Introduction to link database function of cadence OrCAD capture CIS replacement components, graphic tutorial and video demonstration
- Computing the intersection of two planes in PCL point cloud processing (51)
- 【文本分类案例】(4) RNN、LSTM 电影评价倾向分类,附TensorFlow完整代码
猜你喜欢
Project training of Software College of Shandong University - Innovation Training - network security shooting range experimental platform (V)
Handwritten Google's first generation distributed computing framework MapReduce
Livego + ffmpeg + RTMP + flvjs to realize live video
AQS learning
selenium.common.exceptions.WebDriverException: Message: ‘chromedriver‘ executable needs to be in PAT
山东大学软件学院项目实训-创新实训-网络安全靶场实验平台(七)
SQL Server Connectors By Thread Pool | DTSQLServerTP 插件使用说明
aqs的学习
Openharmony open source developer growth plan, looking for new open source forces that change the world!
Servlet learning notes
随机推荐
DNS cloud school | quickly locate DNS resolution exceptions and keep these four DNS status codes in mind
SQL Server Connectors By Thread Pool | DTSQLServerTP plugin instructions
STM32基础知识
山东大学软件学院项目实训-创新实训-网络安全靶场实验平台(七)
Zdns was invited to attend the annual conference of Tencent cloud basic resources and share the 2020 domain name industry development report
Error reported by Azkaban: Azkaban jobExecutor. utils. process. ProcessFailureException: Process exited with code 64
Database query - course selection system
Building googlenet neural network based on pytorch for flower recognition
AQS learning
SQL Server connectors by thread pool 𞓜 instructions for dtsqlservertp plug-in
Redis的安装(CentOS7命令行安装)
Sqoop imports tinyint type fields to boolean type
WordPress插件:WP-China-Yes解决国内访问官网慢的方法
Investigate why close is required after sqlsession is used in mybatties
【文本分类案例】(4) RNN、LSTM 电影评价倾向分类,附TensorFlow完整代码
中金财富公司怎么样,开户安全吗
PIP installation package reports an error. Could not find a version that satisfies the requirement pymysql (from versions: none)
Grafana shares links with variable parameters
Project training of Software College of Shandong University - Innovation Training - network security shooting range experimental platform (6)
Livego + ffmpeg + RTMP + flvjs to realize live video