mysql并行查询语句
简介: 在刚刚结束的乌镇世界互联网大会上,阿里云自研POLARDB云原生数据库当选世界互联网领先科技成果。POLARDB既融合了商业数据库稳定可靠、高性能、可扩展的特征,又具有开源云数据库简单开放、自...
2024.11.15死锁在平时工作中总是很常见,我们又不可能总是实时关注着,那么怎么去把发生死锁的一些情况记录下来呢?
1、配置文件在MySQL 5.6版本中查看死锁,需要执行show engine innodb status\G;命令。
在MySQL 5.6/5.7或MariaDB 10.0/10.1版本中,在my.cnf配置文件里加入:
innodb_print_all_deadlocks=1就可以把死锁信息打印到错误日志里。
2、全局参数mysql> show variables like ‘%deadlock%‘;mysql> set global innodb_print_all_deadlocks=1;3、死锁实验3.1、准备数据
mysql> create table t1(id int,name varchar(20));mysql> insert into t1 values(1,‘b‘);mysql> insert into t1 values(5,‘c‘);mysql> commit;mysql> select * from t1;mysql> create index idx_t on t1(id); --后面update如果条件有索引,锁行,如果没有,锁表3.2、产生死锁
会话1:mysql> select * from t1;mysql> begin;mysql> update t1 set name=‘b1‘ where id=1;会话2:mysql> select * from t1;mysql> begin;mysql> update t1 set name=‘c2‘ where id=5;会话1:mysql> update t1 set name=‘c1‘ where id=5; ----等待会话2:mysql> update t1 set name=‘b2‘ where id=1;ERROR 1213 (40001): Deadlock found when trying to get lock; try restarting transaction会话1:mysql> update t1 set name=‘c1‘ where id=5; ------此时可以发现会话1执行成功3.3、查看错误日志
2019-07-10T15:54:20.474062Z 24 [Note] InnoDB: Transactions deadlock detected, dumping detailed information.2019-07-10T15:54:20.474091Z 24 [Note] InnoDB: *** (1) TRANSACTION:TRANSACTION 35509311, ACTIVE 31 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 5 lock struct(s), heap size 1136, 4 row lock(s), undo log entries 1MySQL thread id 25, OS thread handle 140127543449344, query id 42548 localhost root updatingupdate t1 set name=‘c1‘ where id=52019-07-10T15:54:20.474138Z 24 [Note] InnoDB: *** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 1562 page no 4 n bits 72 index idx_t of table `jpcpdb`.`t1` trx id 35509311 lock_mode X waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 2; compact format; info bits 0 0: len 4; hex 80000005; asc ;; 1: len 6; hex 000000001705; asc ;;2019-07-10T15:54:20.474242Z 24 [Note] InnoDB: *** (2) TRANSACTION:TRANSACTION 35509312, ACTIVE 19 sec starting index readmysql tables in use 1, locked 14 lock struct(s), heap size 1136, 4 row lock(s), undo log entries 1MySQL thread id 24, OS thread handle 140127543981824, query id 42549 localhost root updatingupdate t1 set name=‘b2‘ where id=12019-07-10T15:54:20.474268Z 24 [Note] InnoDB: *** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 1562 page no 4 n bits 72 index idx_t of table `jpcpdb`.`t1` trx id 35509312 lock_mode XRecord lock, heap no 1 PHYSICAL RECORD: n_fields 1; compact format; info bits 0 0: len 8; hex 73757072656d756d; asc supremum;;Record lock, heap no 3 PHYSICAL RECORD: n_fields 2; compact format; info bits 0 0: len 4; hex 80000005; asc ;; 1: len 6; hex 000000001705; asc ;;2019-07-10T15:54:20.474536Z 24 [Note] InnoDB: *** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 1562 page no 4 n bits 72 index idx_t of table `jpcpdb`.`t1` trx id 35509312 lock_mode X waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 2; compact format; info bits 0 0: len 4; hex 80000001; asc ;; 1: len 6; hex 000000001704; asc ;;2019-07-10T15:54:20.474604Z 24 [Note] InnoDB: *** WE ROLL BACK TRANSACTION (2)后面会分享更多devops和DBA方面的内容,感兴趣的朋友可以关注一下~
简介: 在刚刚结束的乌镇世界互联网大会上,阿里云自研POLARDB云原生数据库当选世界互联网领先科技成果。POLARDB既融合了商业数据库稳定可靠、高性能、可扩展的特征,又具有开源云数据库简单开放、自...
2024.11.15【数据查询语言】(1) 查询系统内部函数返回内容和算式计算显示MYSQL的版本:select version();显示当前时间:select now();显示年月日:select DAYOFMONTH...
2024.11.12上节课给大家介绍了MySQL子查询的基本内容,本节课我们准备给大家介绍MySQL的多表联合查询。大家都知道,MySQL多表联合查询包括内连接、外连接、笛卡尔积连接查询三种。今天我们先重点介绍常用的外连...
2024.11.12看如下一条sql语句:# table T (id int, name varchar(20))delete from T where id = 10;MySQL在执行的过程中,是如何加锁呢?在看下面这...
2024.11.15一、关联查询1、概念在查询数据时,所需要的数据不只在一张表中,可能在两张或多张表中。这个时候,需要同时操作这些表来查询数据,即关联查询。关联查询所涉及到的表与表之间都会存在有关联的字段,如员工表的部门...
2024.11.12