2

这似乎是一个非常基本的问题,但我不知道答案。

我用 PHP 编写了一个脚本,它遍历一些数据,然后对我们数据库中的记录执行更新。大约有 150,000 条记录,因此脚本肯定需要一段时间才能完成。

如果我运行基本的 SELECT 语句,我可能会损害或干扰数据插入吗?

说...我想确保脚本正常工作,所以如果我运行一个基本的 SELECT COUNT() 来查看它是否在脚本运行时实时增加。这是可能的还是会搞砸什么?

谢谢!

4

1 回答 1

1

Generally a SELECT call is incapable of "causing harm" provided you're not talking about SQL injection problems.

The InnoDB engine, which you should be using, has what's called Multi-Version Concurrency Control or MVCC for short. It means that until your UPDATE statement is finished, or the transaction that the statement is a part of, the SELECT will be done against the last consistent database state.

If you're using MyISAM, which is a very bad idea in most production environments due to the limitations of that engine and the way the data is stored without a rollback journal, the SELECT call will probably block until the UPDATE is applied since it does not support MVCC.

于 2013-01-24T18:26:36.317 回答