Databases 8 min read

Is ANALYZE TABLE Safe on a Busy MySQL Database Server?

Running ANALYZE TABLE on MySQL, Percona Server, or MariaDB can block queries in older versions, but from MySQL 8.0.24, Percona Server 5.6.38+, 5.7.20+, and MariaDB 10.5.4+, the operation is safe and no longer causes disruptive locks.

Aikesheng Open Source Community
Aikesheng Open Source Community
Aikesheng Open Source Community
Is ANALYZE TABLE Safe on a Busy MySQL Database Server?

When using the ANALYZE TABLE command to manually refresh table and index statistics, it can acquire an exclusive lock on the table definition cache, causing other queries to wait and potentially leading to high latency in production environments.

Historically this issue affected all MySQL versions prior to 8.0.23 and all 5.7 series releases. Example sessions show a slow query waiting for an ANALYZE operation, and vice‑versa.

mysql> select @@version,@@version_comment;
+-----------+------------------------------+
| @@version | @@version_comment            |
+-----------+------------------------------+
| 5.7.43   | MySQL Community Server (GPL) |
+-----------+------------------------------+
1 row in set (0.00 sec)

mysql> show processlist;
+----+----------+-----------+------+---------+------+-------------------------+----------------------------------------------------------------+
| Id | User     | Host      | db   | Command | Time | State                   | Info                                                             |
+----+----------+-----------+------+---------+------+-------------------------+----------------------------------------------------------------+
|  4 | msandbox | localhost | db1  | Query   |   54 | Sending data            | select avg(k) from sbtest1 where pad not like '%f%' group by c |
+----+----------+-----------+------+---------+------+-------------------------+----------------------------------------------------------------+

From MySQL 8.0.24 onward, the lock issue was fixed, and the command completes quickly without blocking other statements. The official documentation notes that ANALYZE TABLE removes the table from the definition cache, requiring a flush lock, but the operation now finishes promptly.

Percona Server for MySQL introduced a fix that eliminates the unnecessary table‑definition‑cache lock. Since Percona Server 5.6.38, 5.7.20 and all 8.0 releases, running ANALYZE TABLE is safe.

MariaDB suffered the same problem in versions prior to 10.5.4. After upgrading to 10.5.4 or newer (or any later series), the lock contention no longer occurs.

Conclusion

As long as your database runs a recent version of MySQL (8.0.24+), Percona Server (5.6.38+, 5.7.20+, 8.0.x+), or MariaDB (10.5.4+), executing ANALYZE TABLE is safe and will not cause unexpected pauses.

MySQLPerconaDatabase performanceMariaDBANALYZE TABLE
Aikesheng Open Source Community
Written by

Aikesheng Open Source Community

The Aikesheng Open Source Community provides stable, enterprise‑grade MySQL open‑source tools and services, releases a premium open‑source component each year (1024), and continuously operates and maintains them.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.