[{"createTime":1735734952000,"id":1,"img":"hwy_ms_500_252.jpeg","link":"https://activity.huaweicloud.com/cps.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905","name":"华为云秒杀","status":9,"txt":"华为云38元秒杀","type":1,"updateTime":1735747411000,"userId":3},{"createTime":1736173885000,"id":2,"img":"txy_480_300.png","link":"https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=edb15096bfff75effaaa8c8bb66138bd&from=console","name":"腾讯云秒杀","status":9,"txt":"腾讯云限量秒杀","type":1,"updateTime":1736173885000,"userId":3},{"createTime":1736177492000,"id":3,"img":"aly_251_140.png","link":"https://www.aliyun.com/minisite/goods?userCode=pwp8kmv3","memo":"","name":"阿里云","status":9,"txt":"阿里云2折起","type":1,"updateTime":1736177492000,"userId":3},{"createTime":1735660800000,"id":4,"img":"vultr_560_300.png","link":"https://www.vultr.com/?ref=9603742-8H","name":"Vultr","status":9,"txt":"Vultr送$100","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":5,"img":"jdy_663_320.jpg","link":"https://3.cn/2ay1-e5t","name":"京东云","status":9,"txt":"京东云特惠专区","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":6,"img":"new_ads.png","link":"https://www.iodraw.com/ads","name":"发布广告","status":9,"txt":"发布广告","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":7,"img":"yun_910_50.png","link":"https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=aXhpYW95YW5nOA===&utm_medium=cps&utm_campaign=201905","name":"底部","status":9,"txt":"高性能云服务器2折起","type":2,"updateTime":1735660800000,"userId":3}]
<>什么是事务
* 事务是数据库系统区别于其他一切文件系统的重要特性之一
* 事务是一组具有原子性的SQL语句,或是一个独立的工作单元
事务需要符合以下特点:
原子性(ATOMICITY),定义:
一个事务必须被视为一个不可分割的最小工作单元,整个事务中的所有操作要么全部提交成功,要么全部失败,对于一个事务来说,不可能只执行其中的一部分操作
一致性(CONSISTENCY),定义:
一致性是指事务讲数据库从一种一致性状态转换到另外一种一致性状态,在事务开始之前和事务结束后数据库数据的完整性没有被破坏
隔离性(ISOLATION),定义:
隔离性要求一个事务对数据库中数据的修改,在未提交完成前对于其它事务是不可见的
SQL标准中定义的四种隔离级别
* 未提交读(READ UNCOMMITED) ,即脏读
* 已提交读(READ COMMITED),大多数数据库中的默认,mysql列外
* 可重复读(REPEATABLE READ)
*
可串行化(SERIALIZABLE),在读取的每一行数据都加锁,会导致大量的锁超时、锁征用问题,在实际业务中很少用到这个隔离级别,除非严格要求数据一致性、可以接受在没有并发的前提下才会考虑使用这种隔离界别
持久性(DURABILITY),定义:
一旦事务提交,则其所做的修改就会永久保存到数据库中。此时即使系统崩溃,已经提交的修改数据也不会丢失
什么是大事务
定义:运行时间比较长,操作的数据比较多的事务
风险:
* 锁定太多的数据,造成大量的阻塞和锁超时
* 回滚时所需时间比较长
* 执行时间长,容易造成主从延迟
如何处理大事务
* 避免一次处理太多的数据
* 移出不必要在事务中的SELECT操作