I have an expensive reporting query that can take 1-20+ seconds to run. (Depending on how much data it has)
Is there a way to kill a mysql process/query from running after a certain amount of time?
I see this:
mysql auto kill query
Is this the best route? I have also read that I should try to improve my queries. I will look into this too, but I am just asking for suggestions on the best route.
First run
show processlist;
then find the query that you want to kill then run
kill "1";
1 is the id of the query you want to kill you have to choose it according to the list
Related
I've executed the copy table operation from PhpMyAdmin and it is taking too long (big table), and now the original and new table are not responding (I can browse the other tables in PhpMyAdmin)
I think because maybe there is a read lock or something worst, is possible to cancel the operation or see at least what's happening?
Two possible things - first, you could restart the webserver to stop any running PHP scripts. That might help if PHPMyAdmin copies the data in batches.
Second, you can execute show full processlist query to see all running queries. Identifying the hung query should not be too hard. Then use kill <pid> query (replace the with the actual process ID) to kill that query.
On phpMyAdmin's main page, go to Status > Processes. You should be seeing one process with a large value under Time; use the Kill link to stop it.
I am using MySQL workbench 6.3 CE. I want to take the snapshots of MySQL status variables.
I want to store the values of status variables after every 1 second during the execution of query.
I can simply show the variables using 'show global status'. But I want to execute it automatically after every 1 second.
You can run a procedure and a query at the same time by having two separate connections. Workbench is a handy tool, but you should learn to use the mysql commandline tool, too.
The query is rather simple. INDEX(l_shipdate) is likely to be the best for it.
The real way to speed up the query (assuming that is your ultimate goal) is to build and maintain a "Summary table" of daily or monthly subtotals. Then sum the sums and sum the counts. Avg is (SUM(sums)/SUM(counts)).
More discussion: http://mysql.rjweb.org/doc.php/summarytables
Be cautious about running (via EVENT or cron) any code that might take longer than the interval time. If it gets behind, it is likely to cascade and bring the server down, or at least slow things down severely. For that reason, I much prefer the WHILE loop.
I used a loop in my php script to run insert queries into my db. The loop was looping thousand times. I stop my php script while it was till running. Nevertheless, my db table keeps on getting populated continously. I guess that there must be a queue. but this is only a guess. So I am wondering if I can stop all the pending queries from being executed? Also I am wondering if it is possible to see that queue somewhere? Thank you in advance for your replies. Cheers. Marc.
There is no queue, unless you were using INSERT DELAYED.
You can kill the process that is inserting the data like this:
Run SHOW PROCESSLIST to find the id of the connecton you want to kill
Then run KILL CONNECTION <thread_id> to kill that connection.
SHOW PROCESSLIST will give you a list of all currently running queries
I have a very slow query that is built by the ORM and I'm curios how could I find out the exact query being executed.
I cannot monitor it from the mysql-slow.log because it never finishes the execution (as in I don't have eternity to wait for it, more than an hour in an still waiting).
Also I cannot get the query from the ORM, just after execution. And the only way I think of getting it is from the process list.
show processlist \G
But my problem is that most of the query is trimmed of, even before the from keyword.
This question has been asked before but with no answer https://stackoverflow.com/questions/3741356/find-queries-from-process-id-mysql-5-1-x
Any suggestions?
If your query is formatted in multiple lines, some MySQL clients will only display the first line. To see full output run SHOW FULL PROCESSLIST; query in MySQL console.
I have some strange bug into a application(or is it the MySQL build?) that causes queries to remain in "locked" state forever, filling up the max number of threads.
I read about setting the wait_timeout variable to kill the "bogus" threads after a period of time. This works ok, but I would like to log the killed queries for further inspection/making sure backup scripts are not killed.
Is there any possibility to do that?
Thanks.
You might be able to use the slow log, but I'm not sure if the problem is that they never complete. Worth a shot.
Also, you may be able to see what's going on by running SHOW FULL PROCESSLIST while you've got dead threads. It should show you what the problem is and what the query was.
If you can simulate this in a development environment, you could also turn on general query logging (which records every statement) and then just tail the log after it crashes.
In the past, I have tagged queries with a unique comment (per query type):
/* Query_12345 */ SELECT ... FROM ... WHERE ... LIMIT ...
A background process would poll SHOW FULL PROCESSLIST and look for any queries that were more than X seconds long, and tagged with Query_NNNNN.
Finally, it would kill them if they went on too long. This allowed the server to breath while we figured out how to optimize the 80,000,000 record table that was slowing things down.