Payments are experiencing issues due to temporary restrictions in Russia. If your payment does not go through, please submit a support request.Our support team is available 24/7 — we are always here to help with hosting and server issues.We are now accepting requests for dedicated server rental and colocation services in our data center.Reminder: we recommend enabling backups for additional data protection.A new VPS/VDS lineup with NVMe storage and improved performance is now available.Maintenance work on some servers has been completed. All services are operating normally.
Article5 min readViews1

How to Check Database Size and Largest Tables in MySQL 8.0

Diagnostic SELECT queries against INFORMATION_SCHEMA to estimate database, data, and index sizes in MySQL 8.0, with an explanation of InnoDB limitations.

Comments 0

A data storage rack with neatly arranged unlabeled drives
In this article

The size of the MySQL directory on disk and the sum of tables in the report may differ. The database uses logs, temporary files, system tables, and free space within table spaces. Therefore, a query against INFORMATION_SCHEMA answers a specific question: how much data and indexes the engine counts for tables, not how many gigabytes the entire server instance occupies.

This guide is intended for MySQL 8.0. The queries only read metadata and do not modify tables. Verified on September 25, 2026, against the official MySQL 8.0 reference manual. There was no live MySQL instance in an isolated environment, so syntax and behavior were cross-checked with documentation, but the actual execution plan and runtime on the test stand were not measured. For a large production server, run these queries during moderate load and under an account with minimal privileges for the required schemas.

View user database sizes

The query sums data and index volumes, excluding system schemas. Results are rounded to megabytes.

SELECT table_schema AS database_name, ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) AS size_mb FROM information_schema.tables WHERE table_schema NOT IN ( 'information_schema', 'mysql', 'performance_schema', 'sys' ) GROUP BY table_schema ORDER BY SUM(data_length + index_length) DESC;

The column data_length reflects data, while index_length reflects indexes. For InnoDB, both values are approximate: they are based on allocated pages. This is normal for planning and locating large objects, but it is not an exact count of useful bytes.

Find the largest tables in the selected database

Replace the placeholder YOUR_DATABASE with the name of the required schema. Do not leave the placeholder in the working query, and do not substitute it together with quotes from untrusted external input.

SELECT table_name, engine, table_rows, ROUND(data_length / 1024 / 1024, 2) AS data_mb, ROUND(index_length / 1024 / 1024, 2) AS index_mb, ROUND((data_length + index_length) / 1024 / 1024, 2) AS total_mb FROM information_schema.tables WHERE table_schema = 'YOUR_DATABASE' AND table_type = 'BASE TABLE' ORDER BY (data_length + index_length) DESC LIMIT 20;

The condition table_type = 'BASE TABLE' excludes views. The limit LIMIT 20 retains the first twenty tables and does not affect the data. The field table_rows for InnoDB is an approximate estimate and may differ significantly from the exact row count.

Separate data from indexes

A large index is not necessarily redundant. It can accelerate critical queries. However, a table where indexes are significantly heavier than the data warrants separate verification: which indexes are used, whether there are duplicate composite keys, and how the record changes.

SELECT table_name, ROUND(data_length / 1024 / 1024, 2) AS data_mb, ROUND(index_length / 1024 / 1024, 2) AS index_mb, ROUND( index_length / NULLIF(data_length, 0), 2 ) AS index_to_data_ratio FROM information_schema.tables WHERE table_schema = 'YOUR_DATABASE' AND table_type = 'BASE TABLE' ORDER BY index_length DESC LIMIT 20;

The function NULLIF protects the calculation from division by zero. The coefficient helps sort candidates but does not prove index redundancy. The decision to remove an index requires analyzing queries, unique constraints, and a backup; this is a separate task not covered in this guide.

Why figures may be outdated

MySQL caches table statistics. By default, the cache validity period can be up to 24 hours. A query against INFORMATION_SCHEMA may return an outdated estimate after a large data load or deletion.

The ANALYZE TABLE team updates statistics, but this is a modification operation for service data that can affect load and query plans. Do not run it automatically just for a pretty report. If fresh estimates are needed, coordinate the window and consequences with the administrator.

What is excluded from table totals

  • Binary logs and replication relay logs.

  • Redo and undo logs, the system tablespace, and InnoDB service files.

  • Temporary tables and temporary query files.

  • Backups, dumps, and application logs located near the database directory.

  • Free space within the shared tablespace that cannot be unambiguously attributed to a single table.

Therefore, for the task of "why the disk is running out," the query is supplemented with a check of the file system and MySQL configuration. For the task of "which tables are growing," it is more useful to save the results of the same query by date and compare the growth.

Criteria for a completed check

  1. The MySQL version and the name of the analyzed schema have been recorded.

  2. Database sizes and the first twenty tables have been retrieved.

  3. Data and indexes were reviewed separately, but no conclusions on deletion were drawn based on a single coefficient.

  4. The time of data retrieval and the possible age of the statistics were noted.

  5. Free disk space was checked separately from the table assessment.

  6. If the growth is unexpected, the table owner and the period for data comparison were identified.

Diagnostic SELECT queries are safer than attempting to shrink a table immediately, but on a large instance, even reading metadata can take time. If the server is already overloaded or replication is lagging, stop after the minimal query and coordinate further steps with the database administrator.

Discussion 0

Share your experience and ask questions. Comments without links appear after editorial review.

No comments yet. Start the discussion.