As others mention, you can log in to your MySQL server, issue SHOW PROCESSLIST
, locate the number for the query you want to abandon, and then issue a KILL number
command.
It seems like you want this function to be self-service for your report-designing users, rather than having them call somebody in your net ops and ask them to do it, or teach them to use an administration tool.
I've done this sort of thing before. It takes three parts.
First, you need to arrange to insert a tag into the kind of queries your users might want to abandon. For example, if your user is doing this
SELECT cust_id, SUM(orders), COUNT(orders)
FROM big_fat_table
GROUP BY cust_id
you'll need to change the text of the query so it has a tag embedded in a comment, for example like so.
SELECT /*report:user2290084*/ cust_id, SUM(orders), COUNT(orders)
FROM big_fat_table
GROUP BY cust_id
Notice this tag has two items in it: report:
and a user id. The user id needs to be something that does not relate to the connection upon which the query is run -- that connection will be tied up if you're trying to abandon the query running on it. The tag doesn't affect the execution of the query at all. It just shows up in the server's process table.
Second: your PDO code that runs those queries is going to need good and user friendly exception handling, because having the queries blow up underneath your code will become routine. You're going to need to experiment with that to get this abandon-query feature to be useful to your users.
Third: issue this query when you need to abandon the report query for user2290084
select id from information_schema.processlist where info like '%/*%report:user2290084*/%'
It looks through the process list to find the process id for a query with the appropriate tag. Then issue
kill <<that process id>>
and you've abandoned the query.
In php, it might look like this:
$q = 'select id from information_schema.processlist where info like :tag';
$tag = '%/*report:' . $userid . '*/%'
$stmt = $dbh->prepare($q);
$stmt->bindParam(':tag', $tag);
$stmt->execute();
$pids = $stmt->fetchAll(PDO::FETCH_COLUMN, 0);
foreach ($pid in $pids) {
$dbh->query('KILL ' . $pid);
}
Notice there's a loop in this code. It's possible that you will have more than one report query running for this user, or none.