10

I have a my.cnf file. In it I see wait_timeout as well as connect_timeout. What's the difference between these 2?

16

Right from the MySQL Documentation

  • wait_timeout : The number of seconds the server waits for activity on a noninteractive connection before closing it.
  • connect_timeout : The number of seconds that the mysqld server waits for a connect packet before responding with Bad handshake

EXAMPLES

  • If wait_timeout is 1800 (30 Minutes), the DB Connection will close in 30 minutes if the connection is idle (indicated by Sleep in the command column of the processlist).
  • If connect_timeout is 10, then mysqld will reject you if you cannot login (authenticate) in 10 seconds.
4
  • There are separate "interactive" and "batch" versions of wait_timeout. Interactive defaults to 8 hours (IIRC); it shows up (at least) when you use the mysql commandline tool.
    – Rick James
    Jan 28 '17 at 16:59
  • concerning wait_timeout whats the best way to see how many db connections are idle eg the default seems to be 8 hours so that must there's a lot of connections just hanging around awaiting timeout Sep 2 '19 at 16:37
  • 1
    so let's say I have a query that takes 2 minutes to run, would MySQL disconnect my connections if wait_timeout is less than 2 minutes? Dec 14 '20 at 7:13
  • 1
    @SoheilRahsaz Anytime a query runs, the idle time start over from scratch. When it is idle for longer than two minutes, then the connection terminates Dec 14 '20 at 19:16
1

wait_timeout is how long to keep a connection as idle state. connect_timeout is how long to wait for a connection to be made.

This is my best understanding, please comment or edit as needed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.