最近工作上发生了一次mysql的deadlock事件,发生死锁的是几个批处理的脚本,没有显示执行transaction,而且是一条一条sql执行的,一次更新或者插入一条记录。以往介绍死锁的案例都是使用事务,然后事务中执行多条sql的,所以面对此情况瞬间蒙蔽。不过也借此机会整理与mysql锁相关的基础知识。
有一个表stat_day,表结构如下(由于实际的数据表不方便直接贴出来,因此进行了修饰)1
2
3
4
5
6
7
8
9
10
11create table stat_day (
money int not null default 0,
statdate datetime not null,
package_code varchar(20) not null default '',
gid varchar(20) not null default '',
cid varchar(20) not null default '',
index statdate(statdate),
index package_code(package_code),
index gid(gid),
index cid(cid)
)
工作中需要统计数据