Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pause and resume running mysql query

Tags:

sql

mysql

I have got quite slow query (actually this is data loading from mysql.dump). Now I want to check how many rows are already loaded.

select count(*) from my_table;

As far as data is loading, my_table is locked, so I can't execute this sql before dump is loaded.

Cmd       ID   State               User   Host           DB      Time   Query                           
Query     191  update              root   localhost      rehub   00:09  INSERT INTO `my_table` VALUES ...
Query     189  Waiting for table   root   localhost      rehub   06:25  select count(*) from my_table

So is there a way to pause query 191, execute query 189 and then resume query 191?

like image 961
fl00r Avatar asked Nov 23 '11 12:11

fl00r


People also ask

How do you pause a SQL query?

Now pause SQL Server by right clicking on the server instance and selecting Pause. It opens up a pop-up window to confirm or cancel the pause operation. Click Yes to go ahead with the pause operation.

How do I stop a running query in mysql?

Run the following command: mysql> SELECT GROUP_CONCAT(CONCAT('KILL ',id,';') SEPARATOR ' ') FROM information_schema. processlist WHERE user <> 'system user'; This will kill all your MySQL queries.


1 Answers

No there is not a way to suspend a query.

If you're doing bulk load work you might want to use a bulk loader that commits every few thousand rows.

Also, using MyISAM instead of InnoDB will alleviate this problem. MyISAM is a good choice for bulk processing where you're not primarily concerned with transactional integrity.

like image 128
O. Jones Avatar answered Oct 03 '22 22:10

O. Jones