我怎样才能从MySQL InnoDB表独特地popup没有种族危害问题?

如何通过行locking/存储过程来改进以下代码。

UPDATE `data` SET status=':temp_status' WHERE account_id = :account_id AND dataset_id=':dataset' AND status=':source' LIMIT $limit; SELECT id,phone,firstname,lastname FROM `data` WHERE account_id = :account_id AND status = ':temp_status'; UPDATE `data` SET status=':destination',status_updated=NOW() WHERE account_id = :account_id AND status = ':temp_status'; 

我基本上是从我的许多客户端的表中读取数据,然后进一步处理,我需要确保每个客户端只抓取一堆唯一的logging,然后不能由其他任何用户获得。

我使用InnoDB表上的多查询从PHP运行这个;

我可以通过行locking来实现吗?

行locking是InnoDB的默认lockingfunction

你可能需要做两件事情:

首先,build立一个交易

 BEGIN TRANSACTION; UPDATE `data` SET status=':temp_status' WHERE account_id = :account_id AND dataset_id=':dataset' AND status=':source' LIMIT $limit; SELECT id,phone,firstname,lastname FROM `data` WHERE account_id = :account_id AND status = ':temp_status'; UPDATE `data` SET status=':destination',status_updated=NOW() WHERE account_id = :account_id AND status = ':temp_status'; COMMIT; 

其次,(这是可选的)在DB会话期间切换事务隔离级别的实验。 这可能会提供所需的数据间歇性。