Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

sleep

mysql

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?

like image 755
Michal M Avatar asked Nov 26 '10 10:11

Michal M


People also ask

What is sleep () in MySQL?

As per MySQL reference manual, “Sleep is the thread waiting for the client to send a new statement to it”. So, a sleep query is the query that waits for the timeout to terminate. That means query which takes time to execute and terminate goes in the sleep status.

How do I put MySQL to sleep?

MySQL – Wait For Seconds Using SELECT SLEEP() WAITFOR DELAY '00:00:05' ; Now the similar code in MySQL can be written in two different ways. DO SLEEP(5);

What is sleep in Processlist?

"Sleep" state connections are most often created by code that maintains persistent connections to the database. This could include either connection pools created by application frameworks, or client-side database administration tools.

How do I make a comment in MySQL?

In MySQL, a comment that starts with /* symbol and ends with */ and can be anywhere in your SQL statement. This method of commenting can span several lines within your SQL.


1 Answers

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

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

like image 174
Konerak Avatar answered Oct 18 '22 16:10

Konerak