dbTalk Databases Forums  

Possible to view last SQL action on a connection?

comp.databases.mysql comp.databases.mysql


Discuss Possible to view last SQL action on a connection? in the comp.databases.mysql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Brian Cryer
 
Posts: n/a

Default Possible to view last SQL action on a connection? - 08-02-2011 , 07:37 AM






Is there any way to view the last SQL that was run on a connection for which
"show processlist" shows the command status as "Sleep"?

I suspect that answer is no, but the reason for asking is that I have a
couple of connections which are being left open with no activity and I'm
sure that this is because the application I'm developing has opened two
connections which have not then been closed. (I'm not otherwise leaking
connections.) Since I've not yet identified any holes in the appliation
logic (although they must be there) I was wondering whether I could see what
the connection was last used for as that would give me a clue as to where in
the application code to look.

Thanks.
--
Brian Cryer
http://www.cryer.co.uk/brian

Reply With Quote
  #2  
Old   
Peter H. Coffin
 
Posts: n/a

Default Re: Possible to view last SQL action on a connection? - 08-02-2011 , 08:00 AM






On Tue, 2 Aug 2011 13:37:40 +0100, Brian Cryer wrote:
Quote:
Is there any way to view the last SQL that was run on a connection for which
"show processlist" shows the command status as "Sleep"?

I suspect that answer is no, but the reason for asking is that I have a
couple of connections which are being left open with no activity and I'm
sure that this is because the application I'm developing has opened two
connections which have not then been closed. (I'm not otherwise leaking
connections.) Since I've not yet identified any holes in the appliation
logic (although they must be there) I was wondering whether I could see what
the connection was last used for as that would give me a clue as to where in
the application code to look.
The General Query Log should be able to provide that information,
provided you've got it turned on. Just look for the entry with the
latest timestamp for the process ID you're interested in.

--
The plural of datum is not "facts".
A collection of facts is not "knowledge".

Reply With Quote
  #3  
Old   
Axel Schwenke
 
Posts: n/a

Default Re: Possible to view last SQL action on a connection? - 08-02-2011 , 08:18 AM



"Brian Cryer" <not.here (AT) localhost (DOT) invalid> wrote:

Quote:
Is there any way to view the last SQL that was run on a connection for which
"show processlist" shows the command status as "Sleep"?
No

Quote:
I suspect that answer is no


Quote:
but the reason for asking is that I have a
couple of connections which are being left open with no activity and I'm
sure that this is because the application I'm developing has opened two
connections which have not then been closed. (I'm not otherwise leaking
connections.) Since I've not yet identified any holes in the appliation
logic (although they must be there) I was wondering whether I could see what
the connection was last used for as that would give me a clue as to where in
the application code to look.
I rather suggest to instrument your application. When it opens a new
connection, it should log the connection id and whatever information
you will need to inspect your code.

The connection id you can get with an API function (mysql_thread_id()
in the C API) or with SELECT CONNECTION_ID()

Another technique is to use different MySQL accounts for different
applications (or even for different aspects of the same application).

Finally you can turn on the general query log, which will record the
complete history of all operations in all connections:

http://dev.mysql.com/doc/refman/5.1/en/query-log.html


XL

Reply With Quote
  #4  
Old   
Brian Cryer
 
Posts: n/a

Default Re: Possible to view last SQL action on a connection? - 08-02-2011 , 09:32 AM



"Axel Schwenke" <axel.schwenke (AT) gmx (DOT) de> wrote

Quote:
"Brian Cryer" <not.here (AT) localhost (DOT) invalid> wrote:

Is there any way to view the last SQL that was run on a connection for
which
"show processlist" shows the command status as "Sleep"?
snip
Finally you can turn on the general query log, which will record the
complete history of all operations in all connections:

http://dev.mysql.com/doc/refman/5.1/en/query-log.html
Thank you Axel (and Peter), I think the general query log should give me
what I need.
--
Brian Cryer
http://www.cryer.co.uk/brian

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.