delete from YOUR_TABLE where id not in (select id from (select max(id) as id from YOUR_TABLE group by UNIQUE_FIELD) as b);
[......]
delete from YOUR_TABLE where id not in (select id from (select max(id) as id from YOUR_TABLE group by UNIQUE_FIELD) as b);
[......]
1. "UPDATE tbl SET count = count - 10 WHERE id = 1"这种SQL能否保证并发事务安全。
答:可以,UPDATE操作会针对id加锁,且"x = x - y"会再最新提交的结果上计算。
演示:
t1
set autocommit = 0;
begin;
update clockin_test set count = count - 10;
t2
set autocommit = 0;
begin;
update cl[......]
ALTER TABLE xxx CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
[......]
转载自:《MySQL的四种事务隔离级别》
一、事务的基本要素(ACID)
转载自:http://www.cnblogs.com/chenwenbiao/archive/2012/06/06/2537508.html
MySQL 使用SELECT ... FOR UPDATE 做事务写入前的确认
以MySQL 的InnoDB 为例,预设的Tansaction isolation level 为REPEATABLE READ,在SELECT 的读取锁定主要分为两种方式:
SELECT ... LOCK IN SHARE MODE
SELECT .[......]