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

MysqlSleep

Mysql Problem Overview


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 Solutions


Solution 1 - Mysql

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 ...

Solution 2 - Mysql

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

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMichal MView Question on Stackoverflow
Solution 1 - MysqlUncle IrohView Answer on Stackoverflow
Solution 2 - MysqlKonerakView Answer on Stackoverflow