MySQL
MySQL
SELECT @@autocommit; -- 1
SET autocommit = 0; -- 关闭:后续语句进入同一事务,需显式 COMMIT
SET autocommit = 1; -- 恢复PostgreSQL
PostgreSQL
SHOW transaction_isolation;
BEGIN;
-- 显式事务块
COMMIT;| MySQL | autocommit=0 后忘 COMMIT:连接归还连接池时未提交数据丢失/长期持锁 |
|---|---|
| PostgreSQL | 无 autocommit 变量;每条独立语句自动提交,BEGIN 后才成事务 |
| 连接池 | 归还连接前确保事务已提交或回滚 |