简介
事务是一组操作的集合,可以提交和回滚,事务中有异常会终止事务,需回滚事务。这组操作要么全部执行成功,要么全部失败
特性 ACID
select @@autocommit;
set @@autocommit=0;
start transaction --begin
-- 事务
select*from account where name='小明'
update account set money=money-1000 where name='小明';
执行出错 ...
update account set money=money+1000 where name='小红';
commit;
rollback;
分类
有read uncommitted read committed repeatable read serializable四种,事务并发造成的问题有脏读,不可重复读,幻读
查看事务隔离级别
select @@tx_isolation
设置事务隔离级别
set session transaction isolation level serializable;