You can run the explain plan for an already-running session. You need to specify the connection ID: To get connection ID, execute:
mysql> SELECT CONNECTION_ID();+-----------------+| CONNECTION_ID() |+-----------------+| 778 |+-----------------+1 row in set (0.00 sec)
mysql> EXPLAIN FORMAT=JSON FOR CONNECTION 778\G*************************** 1. row ***************************EXPLAIN: { "query_block": { "select_id": 1, "cost_info": { "query_cost": "881.04" }, "nested_loop": [ { "table": { "table_name": "employees", "access_type": "index", "possible_keys": [ "PRIMARY" ], "key": "name", "used_key_parts": [ "first_name", "last_name" ], "key_length": "124", "rows_examined_per_scan": 1, "rows_produced_per_join": 1,