When manually running an sql query from an app server, if a user just clicks the X to close the window instead of using F12 or the menu to close the connection to the DB, what kind of negative impact can there be?
.
Is there an automatic timeout for connections?
The timeout of a MySQL connection is defined in the /etc/my.cnf file in the wait_timeout server system variable. It's defaulted to 28800 (seconds) - we usually set it for our clients to a very low value - ranging from 10 seconds to 60 seconds. So, if you leave a connection unclosed, then it'll close, by default, after 28800 seconds (that's very high if you have a large number of clients using the app).
In your case, interactive_timeout doesn't apply, since you are not really using the console.
Related
I'm running a Galera Cluster with a HAProxy-LB in front.
However my users reporting that the session variable wait_timeout is set to 60.
I checked that with
SHOW SESSION VARIABLES LIKE "%wait_timeout%"
and for me the result is wait_timeout 610.
In my /etc/mysql/my.cnf (on every cluster node) the value "28800" is set (as default)
I can confirm that this is used by running:
SHOW GLOBAL VARIABLES LIKE "%wait_timeout%"
as the result is wait_timeout 28800
Any ideas why this does not apply to new sessions? The HAProxy is afaik just a stupid forwarder on port 3306..
Edit: Updated all the packages on all cluster nodes. Still the same issue.
I even tried to check it with the mysql socket connection for root and the new session spawns with a wait_timeout value of 60.
In general the SESSION VARIABLES are initialized to the GLOBAL settings at the time of establishing the connection. After that, either set of settings could be changed.
However, wait_timeout is especially tricky. Not only are there SESSION and GLOBAL, but there are also interactive and batch. Also, InnoDB has a similar value.
610 is an unusual value. Some person or some program must have changed it.
Are you hitting an unexpected limit?
A "ping" can be used to keep the connection alive.
You can check for the connection having gone away, and restart it.
More specifics for you case, please.
I found the issue.
In a different configuration (some admin had made a separate config for "fine tuning" under /etc/mysql/conf.d/finetuning.cnf) was a variable named interactive_timeout which was set to 60. It seems that this one set the session variable of wait_timeout to 60 instead of using the wait_timeout (28800) from the global variables.
Commenting out the interactive_timeout solved the problem for me.
I have a MySQL 5.7.16 running on a Centos 6. I read about these two configuration variables as,
interactive_timeout - interactive time out for mysql shell sessions in
seconds like mysqldump or mysql command line tools.
wait_timeout - the amount of seconds during inactivity that MySQL will
wait before it will close a connection on a non-interactive connection
in seconds.
I set both these variables to 120 seconds in my server which means that after this time, both interactive (mysql shell) and non-interactive (like front end applications) should have their connections get disconnected automatically, if they are in "sleep" mode.
I observed some sessions from the application and other TCP/IP connections from different IDEs like MySQL Workbench running even after 120 seconds. Sometimes they go more than 200 seconds.
Are there any other settings I need to do in my configuration file?
Did you set the GLOBAL variable to 120?
Use
SET GLOBAL wait_timeout = 120
insted
SET wait_timeout= 120
remember that value is refreshed only for new connections.
Run:
SELECT ##global.wait_timeout, ##session.wait_timeout;
to check the real value.
for some reason when I open a connection the the Percona MySQL database on my HostGator website, after fetching the query, it will disconnect/ close the connection about 10 seconds later.
I typically wouldn't care, but HeidiSQL freezes up, preventing exporting or sorting the returned rows with it's UI unless I connect again.
Any thoughts on making the connection last longer? is it something I can do myself, or will it require a dedicated server or some upgrade? (I'm currently on a shared one). Thanks!
Sounds like it may be the "wait" timeout on the MySQL connection.
SHOW VARIABLES LIKE 'wait_timeout'
That's the amount of time (in seconds) that MySQL will leave the session (the database connection) open while it's idle, waiting for another statement to be issued. After this amount of time expires, MySQL can close the connection.
You should be able to change this for a session, to change the timeout to 5 minutes
SET wait_timeout = 300
Verify the setting with the SHOW VARIABLES statement again.
NOTE: This is per connection. It only affects the current session. Every new connection will inherit their own wait_timeout value from the global setting.
(This is only a guess. There's insufficient information in the question to make a precise diagnosis. It could be something other than MySQL server that's closing the database connection, e.g. it could be your connection pool settings (if you are using a connection pool).
I've done the following:
SET GLOBAL wait_timeout = 5;
SET SESSION wait_timeout = 5;
SET GLOBAL interactive_timeout = 5;
SET SESSION interactive_timeout = 5;
But when I run a time consuming query it's still losing the connection at 600 seconds - not 5 seconds. I'm doing the queries in the same MySQL Workbench tab, one after the other, so it should all be in the same session..
I also tried updating C:\Program Files (x86)\MySQL\MySQL Server 5.1\my.ini and adding wait_timeout=5 and... nothing.
Any ideas?
Also, why, when one time consuming query is running on 127.0.0.1 in one tab, can't I do SHOW FULL PROCESSLIST in another tab?
wait_timeout only controls how long a connection can be idle before the server closes it. If you're executing a query that takes a long time, then that variable has nothing to do with your issue.
There is nothing built in to MySQL which will kill active running queries after a set time. So there is something else causing that to happen. And you need to give more information.
When you say "it's closing the connection" What exactly happens? Do you receive an error in your program, if so what is it? How are you running the program?
Hi Any body please tell me , my application has 10 processes , all processes are connects to DB for getting customers details.and my DB wait_timeout value is 30 sec. what will happen when my application is sleep more than wait_timeout value ?
You will get MySQL server has gone away if wait_timeout exceeds.
I think you can use auto reconnect option in your application refer
http://dev.mysql.com/doc/refman/5.0/en/auto-reconnect.html