当前位置:网站首页>MySql事务
MySql事务
2022-06-09 23:32:00 【InfoQ】
事务
-- 1. 查询张三账户余额
select * from account where name = '张三';
-- 2. 将张三账户余额-1000
update account set money = money - 1000 where name = '张三';
-- 此语句出错后张三钱减少但是李四钱没有增加
模拟sql语句错误
-- 3. 将李四账户余额+1000
update account set money = money + 1000 where name = '李四';
-- 查看事务提交方式
SELECT @@AUTOCOMMIT;
-- 设置事务提交方式,1为自动提交,0为手动提交,该设置只对当前会话有效
SET @@AUTOCOMMIT = 0;
-- 提交事务
COMMIT;
-- 回滚事务
ROLLBACK;
-- 设置手动提交后上面代码改为:
select * from account where name = '张三';
update account set money = money - 1000 where name = '张三';
update account set money = money + 1000 where name = '李四';
commit;
START TRANSACTION 或 BEGIN TRANSACTION;COMMIT;ROLLBACK;start transaction;
select * from account where name = '张三';
update account set money = money - 1000 where name = '张三';
update account set money = money + 1000 where name = '李四';
commit;
四大特性ACID
- 原子性(Atomicity):事务是不可分割的最小操作但愿,要么全部成功,要么全部失败
- 一致性(Consistency):事务完成时,必须使所有数据都保持一致状态
- 隔离性(Isolation):数据库系统提供的隔离机制,保证事务在不受外部并发操作影响的独立环境下运行
- 持久性(Durability):事务一旦提交或回滚,它对数据库中的数据的改变就是永久的
并发事务
- √表示在当前隔离级别下该问题会出现
- Serializable 性能最低;Read uncommitted 性能最高,数据安全性最差
SELECT @@TRANSACTION_ISOLATION;SET [ SESSION | GLOBAL ] TRANSACTION ISOLATION LEVEL {READ UNCOMMITTED | READ COMMITTED | REPEATABLE READ | SERIALIZABLE };边栏推荐
- 虚拟机环境配置记录1
- 2022-06-10日报: 华为十大发明公布:高效加法网络、多目标博弈智能驾驶获奖
- IEEE 754浮点数标准详解
- Deploy MySQL based on statefulset in kubernetes (Part 1)
- MySQL定时任务(Event Scheduler)
- PHP学习需要掌握的基础与入门知识
- C# WPF布局控件LayoutControl介绍
- C# WPF从后台代码生成行列可变的表格
- Retrofit2.0 添加Header的方法总结
- Difference between stacked cable optical module and ordinary optical module
猜你喜欢
随机推荐
numpy基础操作
Q-learning
"When you are no longer a programmer, many things will get out of control" -- dialogue with SUSE CTO, the world's largest independent open source company
10 common high-frequency business scenarios that trigger IO bottlenecks
POI exporting Excel
Record the 'new' course of an emergency investigation
蓝桥杯_分割立方体_组合数学_加法原理
Introduction à Tencent - ncnn
彭博终端产品覆盖的加密资产数量扩大为前50名资产
AI首席架构师5-AICA-文心NLP大模型技术及应用
The latest activity openharmony open source developer growth plan solution student challenge is about to start!
Introduction to C # WPF layout control layoutcontrol
C# WPF UI框架MahApps切换主题
MySQL定时任务(Event Scheduler)
opencv体系结构
"At the age of 35, I have no sideline, so I'm embarrassed to mix in the workplace": get rid of the sideline of dead salary recommendation
2022 love analysis · privacy computing vendor panoramic report | love Analysis Report
C# WPF从后台代码生成行列可变的表格
使用打印机打印东西打印不全怎么办
Core [email protected] < 3.4 is no longer maintained and not recommended for usage due to the









