死锁
一个例子就可以明白
-- 事务A USE sql_store; START TRANSACTION; UPDATE products SET property = 'xxx' WHERE product_id = 1; UPDATE orders SET order_name = 'xxx' WHERE order_id = 1; COMMIT;
-- 事务B USE sql_store; START TRANSACTION; UPDATE orders SET order_name = 'xxx' WHERE order_id = 1; UPDATE products SET property = 'xxx' WHERE product_id = 1; COMMIT;
事务A执行到 UPDATE orders 然后事务B开始执行了,这时候事务A必须得等事务B执行完,事务B执行到 UPDATE products,发现这条数据被事务A锁住了,事务B就得等事务A执行完,这样就会产生死锁。
避免死锁...
将事务按照相同的顺序编写...
简化事务,缩短运行时长