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?
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.
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);
"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.
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.
SELECT ... SELECT SLEEP(5); SELECT ...
But what are you using this for? Are you trying to circumvent/reinvent mutexes or transactions?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With