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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4284524/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 17:49:09  来源:igfitidea点击:

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

mysqlsleep

提问by Michal M

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

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

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

从我收集阅读 MySQL Dev 论坛和 MySQL Docs 中非常模糊的描述来看,我不能这样使用它:

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

So what is it good for then?

那么它有什么用呢?

回答by Konerak

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

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

但是你用这个做什么?您是否试图规避/重新发明互斥锁或事务?

回答by Uncle Iroh

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.

如果你不想SELECT SLEEP(1);,你也可以DO SLEEP(1);在你不想看到输出的过程中的那些情况下很有用。

e.g.

例如

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