473,387 Members | 3,787 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

query timeout

It looks like mysql doesn't have the ability to set a query timeout. Is
this true? So in the mean time I created the following perl DBI script
to do it for me.

#!perl

# DBI service name
use constant DSN => "dbi:mysql:ABC:localhost";

# database username
use constant DBUSER => "root";

# database password
use constant DBPASS => "XYZ";

# seconds application should wait before checking again
use constant SLEEP => 5;

# maximum seconds before script kills a query
use constant TIMEOUT => 10;

# hash of usernames that will be checked
my %USERS = ( foo => 1 );

# END OF CONFIG
use strict;
use DBI;
my ($dbh, $read_sth, $kill_sth);
$dbh = DBI->connect(DSN,DBUSER,DBPASS,
{ PrintError => 1, RaiseError => 1, AutoCommit => 1 }) or die
$DBI::errstr;
$read_sth = $dbh->prepare("SHOW FULL PROCESSLIST");
$kill_sth = $dbh->prepare("KILL ?");
print STDERR "Killed Statements:\n";
while (1) {
$read_sth->execute();
while (my ($id, $user, $host, $db, $cmd, $time, $state, $info)
= $read_sth->fetchrow_array()) {
if (exists $USERS{$user} && $time > TIMEOUT &&
$cmd eq 'Query' && $state eq 'Sending data') {
print STDERR "Id: $id\nUser: $user\nHost: $host\nDB:
$db\nCommand: $cmd\nTime: $time\nState:
$state\nInfo:\n$info\n---------------------------------------------------------------------\n";
$kill_sth->execute($id);
}
}
sleep SLEEP;
}

Jul 28 '05 #1
0 9394

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Stefano | last post by:
Hi everibody, it's the first time i post on this newsgroup. I'm Stefano from Milano, italy. I'm a beginners with Sql2000. My problem is this. I run a View using enterprise manager and after less...
0
by: Abram Friesen | last post by:
Hi all, I'm writing an ODBC application on NT Server, accessing a db2 udb v 8.1.6 database on AIX. I'd like to issue a query, and if the table/page/row is locked, to timeout instantly, rather...
4
by: Robert | last post by:
Greetings I am assisting a developer with an Access application performance problem and an ODBC timeout. In a nutshell they have a combo box with a drop down that queries a lookup table on a SQL...
3
by: Stijn Vanroye | last post by:
Hi List, I'm running a query on a not-so-small db. Mostly this query runs fast enough, but every once in a while the query takes a long time to complete in wich case the users start banging away...
1
by: traceable1 | last post by:
I have 2 SQL databases which are the same and are giving me different query plans. select s.* from hlresults h inner join specimens s on s.specimen_tk = h.specimen_tk where s.site_tk = 9 and...
1
by: msmith | last post by:
MSSQL Server 2000 SP3 in both houston and memphis I have a database in houston, lets call it RED. Specific tables from database RED are copied to database BLUE. Database BLUE is then backed...
0
by: laurenquantrell | last post by:
I have a table with 6 million rows. I'm trying to perform a group by query that incudes a row count of the PK column: SELECT COUNT(DataID) AS Cnt, Column1Name FROM dbo.TableName WHERE...
2
by: laurenquantrell | last post by:
I have a table with 6 million rows. I'm trying to perform a group by query that incudes a row count of the PK column: SELECT COUNT(DataID) AS Cnt, Column1Name FROM dbo.TableName WHERE...
1
by: nilaangel78 | last post by:
Hi, I am developing winforms project using vb.net. In this i am connecting SQL 2000 DB using odbc connection. When i run SQL select query i am getting timeout error. But the same select query...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.