How and when to use SLEEP() correctly in MySQL?

2020-05-20 05:25发布

In relation to my other question today I am wondering how to use MySQL's SLEEP(duration) correctly.

From what I gathered reading MySQL Dev forums and very vague description in MySQL Docs I can't use it this way:

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

So what is it good for then?

标签: mysql sleep
2条回答
迷人小祖宗
2楼-- · 2020-05-20 05:37

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 ...
查看更多
手持菜刀,她持情操
3楼-- · 2020-05-20 05:46
SELECT ...
SELECT SLEEP(5);
SELECT ...

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

查看更多
登录 后发表回答