当前位置:网站首页>MySQL closes the problem of automatic submission of connection transactions
MySQL closes the problem of automatic submission of connection transactions
2022-07-27 01:20:00 【Zero rounding】
In today's independent experiment , It is found that the statement of automatically submitting transactions when the database closes the connection has not been realized in the experiment , Therefore, looking up a lot of data, we have the following results .
MySQL Transactions are automatically committed by default , When we need to rollback a transaction, we need to automatically commit and close the transaction , You can set... With the following command :
set AutoCommit = 0;After the transaction is completed, you can submit it with the following command :
commitWhen closing the database connection , Transactions are also automatically committed , But at this time Automatic submission must be restored to true, Prove the following :
- When the automatic submission of the database is false when , Change data in table , Close the database directly , The data in the query table remains unchanged .
Initial data in the table :

Change the database to be automatically submitted as false:
![]()
Modify the data in the table :
![]()
Close the connection directly :

Reconnect and query the data :

here , We find that the data in the table has not changed , That is to say, the transaction is not automatically committed when the connection is closed .
- When the automatic submission of the database is false when , Change data in table , At this time, change the automatic submission of the database to true, Then close the database connection , The data in the query table has changed .
Initial data in the table :

Change the database to be automatically submitted as false:
![]()
Modify the data in the table :
![]()
Then change the database to be automatically submitted as true:
![]()
Close the connection :

Query the data in the table :

At this time, we find that the data in the table has changed , That is, the database automatically commits the transaction .
Access to information , Find the following code :
if (!skipLocalTeardown) {
if (!this.getAutoCommit() && issueRollback) {
try {
this.rollback();
} catch (SQLException var21) {
sqlEx = var21;
}
}
skipLocalTeardown and issueRollback stay close When calling, the default is false, We can see that when auto submit is turned off , When the connection is closed rollback Instead of submitting automatically . So I guess whether it is necessary to automatically commit transactions when closing the connection autoCommit by true Under the circumstances .
summary :
MySQL You want to automatically commit transactions when your database connection is closed , Be sure to set automatic submission to... Before closing the connection true
边栏推荐
- Doris or starrocks JMeter pressure measurement
- Wu Enda's in-depth learning series teaching video learning notes (I) -- logistic regression function for binary classification
- 李宏毅机器学习(2017版)_P13:深度学习
- 李宏毅机器学习(2017版)_P14:反向传播
- 07 - setup and attack of log server
- SQL学习(2)——表的基础查询与排序
- Verilog procedure assignment statement
- adb shell截屏录屏命令
- Naive Bayes Multiclass训练模型
- Jenkins--基础--03--安装后设置向导
猜你喜欢

Jenkins--基础--5.1--系统配置--插件管理

李宏毅机器学习(2017版)_P1-2:机器学习介绍

SQL relational algebra - Division

Li Hongyi machine learning (2017 Edition)_ P13: deep learning

李宏毅机器学习(2017版)_P14:反向传播

5.xshell连接服务器拒绝访问,密码错误

Tencent upgrades the live broadcast function of video Number applet. Tencent's foundation for continuous promotion of live broadcast is this technology called visual cube (mlvb)

Understanding of Flink interval join source code

Jenkins--基础--5.3--系统配置--全局安全配置

Doris or starrocks JMeter pressure measurement
随机推荐
Warning: IPv4 forwarding is disabled Networking will not work.
Verilog的基本语法
Flink1.11 multi parallelism watermark test
ContextCompat.checkSelfPermission()方法
吴恩达深度学习系列教学视频学习笔记(一)——用于二分类的logistic回归函数
随着5G越来越普及,我们的生活会受到哪些积极的影响
Flinksql window triggered in advance
初中高三部曲音视频下载Pronunciation Pairs+Ship or Sheep+Tree or Three
SQL学习(2)——表的基础查询与排序
快来帮您一分钟了解移动互联网
Play guest cloud brush machine 5.9
As 5g becomes more and more popular, what positive effects will our lives be affected
李宏毅机器学习(2017版)_P21:卷积神经网络CNN
x 的平方根
Deep understanding of pod objects: basic management
Game project export AAB package upload Google tips more than 150m solution
Jenkins--基础--5.1--系统配置--插件管理
DataNode Decommision
2. 错误的里程表
做题笔记1