MySQL – Wait For Seconds Using SELECT SLEEP()

For a WAIT FOR test in MySQL, I use SLEEP with a bounded delay. A customer asked for the corresponding command.

A vessel rests for a deliberate interval while its tools remain available nearby.

-- MySQL alternatives, choose one for a controlled test:
SELECT SLEEP(5);
-- DO SLEEP(5);
-- SQL Server alternative, shown separately:
-- WAITFOR DELAY '00:00:05';

SELECT SLEEP(5) returns zero after uninterrupted completion. DO SLEEP(5) evaluates without a result set. I prefer DO when no return value is needed.

Interruption, timeout and surrounding query context affect results or errors. Client elapsed time need not equal exactly five seconds. Keep MySQL and SQL Server syntax in their separate connections.

Use deliberate timing tests with bounded waits. A sleeping transaction can retain locks, and concurrent sleepers consume resources. Waiting does not cure a slow query or provide a complete retry strategy.

Reference: MySQL SLEEP behavior.

Related reading

A requested delay is not an exact client-duration guarantee, it is deliberate waiting whose context and interruption behavior matter.

Published by Pinal Dave on SQLAuthority. More of my work at pinaldave.com.


Discover more from SQL Authority with Pinal Dave

Subscribe to get the latest posts sent to your email.

MySQL, SQL Scripts
Previous Post
Parquet Exports From SQL Server 2022 With CETAS
Next Post
Login Database Access: List the Databases a Login Can Open

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.