事务操作
mysql默认是自动提交事务
select @@autocommit;//查看当前是否是自动提交事务
set @@autocommit=0;//将事务提交方式改为手动
事例:
select @@autocommit; set @@autocommit=0; update student set no=no-1 where name ='蔡徐坤'; update student set no=no+1 where name ='蔡2坤'; /*提交事务*/ commit ;
update student set no=no-1 where name ='蔡徐坤'; update student set no=no+1 where name ='蔡2坤'; 程序出现错误 /*提交事务*/ commit ; /*回滚事务*/ rollback;
如果不修改事务提交方式
/*开启事务*/ start transaction; /*或者*/ begin ; /*提交事务*/ commit; /*回滚事务*/ rollback;
事务隔离级别
select @@transaction_isolation; set session transaction isolation level read uncommitted; set session transaction isolation level serializable;