如何以及何时在 MySQL 中正确使用 SLEEP() ?

关于今天的 我的另一个问题,我想知道如何正确使用 MySQL 的 SLEEP(duration)

从我收集的 MySQL 开发论坛和 MySQL 文档中非常模糊的描述来看,我不能这样使用它:

SELECT ...
SLEEP(1); /* wait for a second before another SELECT */
SELECT ...

那它有什么用呢?

176333 次浏览
SELECT ...
SELECT SLEEP(5);
SELECT ...

But what are you using this for? Are you trying to circumvent/reinvent mutexes or transactions?

If you don't want to SELECT SLEEP(1);, you can also DO SLEEP(1); It's useful for those situations in procedures where you don't want to see output.

e.g.

SELECT ...
DO SLEEP(5);
SELECT ...