Skip to content
Advertisement

Select query on MYSQL table taking long time and getting timed out

I have a mysql table with 2 million rows, when I’m running any select query on the table it’s taking long time to execute and ultimately it does not return any result.

I have tried running select query from both Mysql Workbench and terminal, it’s the same issue happening.

Below is the table:

And below is the select query i’m running :

even with a limit 1 is also taking long time and not returning a result, its getting timed out :

Could anyone tell me what can be the real reason here?

Also I would like to mention: before I was running these select queries, there was an alter table statement executed on this table which got timed out after 10 minutes and table remained un-altered.

Following is the alter statement:

Note: Using MYSQL version 5.7.24 and Mysql running on Linux Docker container.

Advertisement

Answer

So I got this resolved:

There was Java batch program which was executing a query on the same table for long time and was holding a lock on the table. I found this through “processlist” table of information_schema.

Had to kill the long running query through terminal:

Then it released the lock on that table and all got resolved.

Got help from below SO answers:

  1. Unlocking tables if thread is lost
  2. How do I find which transaction is causing a “Waiting for table metadata lock” state?
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement