473,395 Members | 1,613 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,395 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 9398

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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.