mysql:5.5
mysql> show variables like '%iso%';
+---------------+-----------------+
| Variable_name | Value |
+---------------+-----------------+
| tx_isolation | REPEATABLE-READ |innodb引擎
场景:
mysql> select * from t1;
+------+------+---------------------+
| c1 | c2 | c3 |
+------+------+---------------------+
| 1 | 2 | 2017-11-08 10:24:19 |
| 3 | 4 | 2017-11-08 10:24:26 |
| 5 | 6 | 2017-11-08 10:24:32 |
+------+------+---------------------+
3 rows in set (0.00 sec)
mysql> select * from t2;
+------+------+---------------------+
| c1 | c2 | c3 |
+------+------+---------------------+
| 5 | 6 | 2017-11-08 10:25:10 |
| 7 | 8 | 2017-11-08 10:25:18 |
+------+------+---------------------+
mysql> show create table t1\G
*************************** 1. row ***************************
Table: t1
Create Table: CREATE TABLE `t1` (
`c1` int(11) DEFAULT NULL,
`c2` int(11) DEFAULT NULL,
`c3` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
KEY `idx01` (`c3`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
1 row in set (0.00 sec)
mysql> show create table t2\G
*************************** 1. row ***************************
Table: t2
Create Table: CREATE TABLE `t2` (
`c1` int(11) DEFAULT NULL,
`c2` int(11) DEFAULT NULL,
`c3` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
KEY `idx01` (`c3`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
1 row in set (0.00 sec)
mysql> begin;
Query OK, 0 rows affected (0.00 sec)
mysql> update t1,(select c1,sum(c2) 'c2' from t2 where c3 between '2017-11-08 00:00:00' and '2017-11-08 23:59:59' group by c1) as tmp2
-> set t1.c2=tmp2.c2
-> where t1.c1=tmp2.c1;
Query OK, 0 rows affected (0.00 sec)
Rows matched: 1 Changed: 0 Warnings: 0
卡住,发生阻塞.
会话二:
mysql> begin;
Query OK, 0 rows affected (0.00 sec)
mysql> insert into t2 values(10,11,now());
解决方式:
在执行时间较长的会话加入隔离级别设置,比如在会话1中加入:set tx_isolation='READ-COMMITTED'(会话级别);
mysql 采用内嵌视图更新表引起的1205报错
原创mb646da62f0d7e4 ©著作权
©著作权归作者所有:来自51CTO博客作者mb646da62f0d7e4的原创作品,请联系作者获取转载授权,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
MySQL主从复制报错 Errno 1205
一条SQL导致主从报错1025
MySQL 主从复制 Error