MySQL Slow Query Log
The MySQL Slow Query Log helps you identify database queries that take longer than expected to complete. By reviewing these entries, you can find inefficient SQL statements, understand how they affect database performance, and identify opportunities to optimize your WordPress site.
Viewing the MySQL Slow Query Log
To access the MySQL slow query log:
Navigate to the website overview screen by selecting / clicking on the related card in the Websites screen.
Verify the environment you want to apply the change, Production or Staging by checking out the currently selected environment in the navigation bar.
Click on the Logs → MySQL Slow Logs menu.
The log viewer displays recent slow queries in real time and provides detailed information for each entry. You can expand individual log entries to view detailed execution information and collapse them again to keep the log easy to navigate.
Each log entry appears as a single line that summarizes the query. Selecting the expand icon displays the complete log entry and additional execution details.
When a log entry is expanded, automatic scrolling pauses so you can review the details without interruption. SQL queries are automatically displayed with syntax highlighting, you can toggle this via the related switch
Highlight Colorsin the controls toolbar.The log automatically refreshes with new entries as they are generated, providing a live view of database activity. If you expand a log entry to review its details, automatic scrolling pauses so you can inspect the information without interruption.
Use the search field to find specific text within the log. Matching terms are highlighted throughout the displayed entries, making it easier to locate queries, database names, or other relevant information.
You can copy the complete SQL statement directly from a log entry using the Copy Query action. This is useful when you want to review, test, or troubleshoot the query in a database client (like the one provided in the Dashboard / PHPMyAdmin).
To analyze how MySQL executes a query, use the Copy EXPLAIN action. This generates an EXPLAIN version of the query that you can run through PHPMyAdmin (Database → Go to PHPMyAdmin) to review the execution plan and identify possible performance improvements.
You can quickly jump to the beginning or end of the log, using the navigation controls in the bottom of the screen, to make it review either historical or newly generated entries.
If you need to perform offline analysis or share the log with others, you can download the complete MySQL Slow Query Log for the recent past days.
Information included in each log entry
Each expanded entry provides detailed execution information for the query.
Timestamp : The exact time when the query was executed.
RID: The request identifier associated with the request that generated the query. This is useful when correlating database activity with application or access logs.
Database: The database where the query was executed.
Query: The complete SQL statement. SQL syntax highlighting makes the query easier to read.
Query ID: The internal identifier assigned to the query.
Rows Examined: The total number of rows MySQL inspected while executing the query.
Rows Sent: The number of rows returned to the client.
Rows Affected: The number of rows inserted, updated, or deleted.
Bytes Sent: The amount of data returned to the client.
Lock Time: The amount of time the query spent waiting for table or row locks.
Total Time: The total execution time of the query.
Query Timestamp: The Unix timestamp recorded by MySQL when the query was executed.
What should you review first?
Not every slow query requires optimization. Focus on the values that typically have the greatest impact on performance.
Total Time
This is the overall execution time of the query. Long execution times indicate queries that are consuming database resources and may affect overall site responsiveness. Queries taking several seconds or longer should generally be investigated.
Rows Examined
Rows Examined is often the most important metric when evaluating query efficiency. This value shows how many rows MySQL had to inspect before producing the result.
For example:
Rows Examined: 11,798,762
Rows Sent: 0
This indicates MySQL scanned nearly 12 million rows but returned no results. Large differences between Rows Examined and Rows Sent often suggest that indexes are missing or that the query cannot efficiently locate matching rows.
Lock Time
Lock Time indicates how long the query waited for database locks. A high Lock Time may point to contention between multiple queries or long running transactions.
The SQL query
Review the SQL statement itself. Look for:
Missing WHERE conditions
Multiple JOIN operations
SELECT DISTINCT used on large datasets
ORDER BY or GROUP BY operations on large tables
Functions applied to indexed columns
Subqueries that could be rewritten
Using EXPLAIN to identify performance improvements
Each expanded log entry includes a Copy EXPLAIN action that wraps the query statement in an EXPLAIN statement ready to be copied into PHPMyAdmin. This makes it easy to analyze how MySQL executes the query. `EXPLAIN` tells MySQL to display the execution plan instead of executing the query. The execution plan shows:
Which tables are accessed
The order in which tables are joined
Which indexes are used
Whether full table scans occur
Approximately how many rows MySQL expects to examine
This information helps identify inefficient query execution.
Running EXPLAIN
Expand the slow query.
Select
Copy EXPLAIN.Open Database Management (PHPMyAdmin) (Database → Go to PHPMyAdmin)
Expand the database view and paste the statement into the Query field.
Execute the EXPLAIN statement.
Review the execution plan.
What to look for in the EXPLAIN output:
Full table scans
If the `type` column displays `ALL`, MySQL is scanning every row in the table. This is often the first sign that an index could improve performance.
Missing indexes
Check the `key` column. If it is empty or `NULL`, MySQL did not use an index. Adding an index to frequently filtered or joined columns may significantly reduce execution time.
High estimated row counts
Review the `rows` column. Large estimated row counts usually indicate that MySQL expects to examine many records before finding matching results.
Temporary tables and filesorts
The `Extra` column may include messages such as:
Using temporaryUsing filesort
These operations are not always problematic, but they can become expensive on large datasets.
Common ways to improve slow queries
Depending on the EXPLAIN results, you may be able to improve performance by:
Adding indexes to columns used in WHERE, JOIN, ORDER BY, or GROUP BY clauses.
Reducing the number of rows scanned by making filters more selective.
Avoiding SELECT DISTINCT when it is unnecessary.
Returning only the columns your application needs instead of using `SELECT *`.
Simplifying complex JOIN operations where possible.
Breaking very large queries into smaller operations when appropriate.
⚠️ Before adding indexes: Creating MySQL indexes can be a resource-intensive operation, especially on large or busy sites. During index creation, the database might experience increased CPU, disk I/O, or temporary query slowdowns, which can affect your site's performance and stability. If possible, consider creating indexes during a maintenance window and/or testing the changes in a staging environment first.
Troubleshooting workflow
When reviewing a slow query, a good workflow is:
Identify queries with the highest Total Time.
Compare Rows Examined with Rows Sent.
Review the SQL statement for inefficient patterns.
Run EXPLAIN.
Look for full table scans, missing indexes, and large row estimates.
Apply optimizations and test the query again.
Continue monitoring the Slow Query Log to verify that execution time has improved.
Following this process helps you identify the queries that have the greatest impact on database performance and prioritize optimization efforts effectively.
