How to fetch MYSQL connection time - mysql

How to find out MYSQL connection time not connection_timeout?
I am able to find out the connection timeout value using
SHOW VARIABLES LIKE 'connect_timeout'
But I am not able to get the variable for connection time.

Related

are session variables saved after query execution when using connection pool?

I am struggling to understand how session variables are managed when using a connection pool on every documentation I am reading the definition of session variable is
Session variables
Session variables are set in the scope of your session with the MySQL
server.
A session starts with a connection to the server and ends when the
connection is closed.
Variables go out of scope once the connection is terminated.
for example :
http://www.java2s.com/Tutorial/MySQL/0201__Procedure-Function/LOCALSESSIONANDGLOBALVARIABLESINMYSQL.htm
if we're using a connection pool the connection is not really getting close or terminated
does it mean we need to reset the session variable at the end of the transaction?

How does MariaDB work with maintaining db connection?

I am using Peewee ORM to update and modify database table from my python project.
I have set max connection limit to 15 using:
set global max_connections = 15
to get total connection I run the command,
> select count(*) from information_schema.processlist;
> 12
now that connection limit is 15 and even if I run a my code to do some work on db by opening a connection the number of connection goes up by 2
> select count(*) from information_schema.processlist;
> 14
now even if am done doing the task, I close python terminal I still see total number of connection from process list count to be 14, it seems like old connections get reused or what, if I run the same command to update db table, from different terminal I add 2 more connection but it gives error saying too many connections. but the first terminal I had opened still work.
I can post peewee code if required.
If you are using the regular MySQLDatabase class, then calling .close() on the connection will close it.
On the other hand if you are using PooledMySQLDatabase, .close() will recycle the connection to the pool of available connections. You can manage the connections in the pool using the following APIs: http://docs.peewee-orm.com/en/latest/peewee/playhouse.html#PooledDatabase

Detect when DB server goes down during JDBC query

My application makes queries to MySQL using JDBC. Sometimes, while a query is running, connectivity will be lost to the server. Rather than detecting this and throwing an exception, the code hangs until the TCP connection finally times out (which takes over 10 minutes)
Setting a query timeout doesn't work. If the DB server stays up this will timeout queries, but does nothing if the server goes down before the timeout triggers.
Setting socketTimeout in the MySQL connection string or invoking .withNetworkTimeout on the Connection object sort of works. This does force the connection to timeout if no response is received after the specified timeout, however it will also kill queries that run longer than the timeout even if the DB server is up. I want to die fast if the DB server goes down but still be able to run long queries.
If I could get at the sockets Keepalive settings so I could set the interval/number of probes lower and that would solve the problem, but I can't see anyway to do that with the MySQL JDBC driver.
How can I cause queries to fail quickly when the DB server goes down, while still being able to run long queries?

HostGator mySQL connection time-outs after 10 seconds or so ---- how do I extend this?

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).

Mysql connection timeout in doctrine

I have developed a application which send large number of emails to different users in batches. The most common problem I faced in this application is the problem of mysql connection timeout. In between the batches when there is no queries executed in the previously opened connection and connection remained idle for long time, mysql itself close the connection. After sending the current batch when I again try to execute any sql query it gives me mysql connection error.
Right now I am using mysql_ping($conn) function to check whether the connection id timedout or not. If the connect is timed out I connect again with mysql_connect() function. Now I am moving to doctrine rather than native PHP function. Is there a recconnect() function in Doctorine as well ?
Never faced this problem with my batch actions but I think you could probably do something like this in those places in your code where you think there's a risk the connection will time out:
// Fetch current connection
$conn = Doctrine_Manager::connection();
if(!$conn) {
// Open a new connection
$conn = Doctrine_Manager::connection('mysql://username:password#localhost/whatever', 'connection 1');
}
http://docs.doctrine-project.org/projects/doctrine1/en/latest/en/manual/connections.html
There's a custom bundle that allow connection to reopen:
https://github.com/facile-it/doctrine-mysql-come-back
You can set a maximum amount of retry, or you can manually call method retry on Connection!