User Agents

Web browsers and everyday web tech, explained

Get Size Databases MySQL Query Browser

· 5 min read · Browsers

In this article
  1. Understanding MySQL Database Size Components
  2. How to Query Database Size in MySQL
  3. MySQL Query Browser vs Modern Tools
  4. Accuracy and Limitations of Size Queries
  5. Common Problems and Fixes
  6. Alternatives and Command-Line Methods
  7. Frequently Asked Questions

To get the size of databases in MySQL using MySQL Query Browser or similar tools, run a SQL query against the information_schema database that calculates data and index lengths. The most accurate method uses a SELECT statement summing DATA_LENGTH and INDEX_LENGTH grouped by table schema.

Understanding MySQL Database Size Components

MySQL database size is not a single number but a sum of multiple components: data length, index length, and overhead from fragmentation or temporary tables. Data length refers to the actual content stored in tables, while index length covers all indexes created to speed up queries. Overhead includes unused space from deleted rows, temporary sort tables, or table maintenance gaps. Understanding these elements helps interpret size reports correctly and avoid underestimating storage use.

For example, a table with 10 GB of data might have 3 GB of indexes if it has many foreign keys or full-text indexes. The total disk usage could be even higher if the storage engine (like InnoDB) uses additional space for transaction logs or buffer pools. However, those engine-level files aren’t directly counted in schema-level queries and must be checked separately via file system inspection.

How to Query Database Size in MySQL

The standard way to get database sizes is by querying the information_schema.TABLES table. This built-in system table stores metadata about all tables, including row counts, engine type, and storage sizes. To calculate total size per database, use the following query:

  1. Open MySQL Query Browser or any MySQL client (like MySQL Workbench, phpMyAdmin, or command-line client).
  2. Connect to the MySQL server with a user that has access to information_schema.
  3. Run this SQL query:
SELECT 
  TABLE_SCHEMA AS 'Database',
  ROUND(SUM(DATA_LENGTH + INDEX_LENGTH) / 1024 / 1024, 2) AS 'Size (MB)'
FROM 
  information_schema.TABLES 
WHERE 
  TABLE_SCHEMA NOT IN ('information_schema', 'performance_schema', 'mysql', 'sys')
GROUP BY 
  TABLE_SCHEMA;

This query returns each database name and its total size in megabytes. The division by 1024 twice converts bytes to kilobytes then megabytes. Filtering out system databases avoids clutter. You can adjust the divisor to get sizes in gigabytes (divide by 1024 three times) or include system databases by removing the WHERE clause.

MySQL Query Browser vs Modern Tools

MySQL Query Browser was an older GUI tool from Oracle, discontinued around 2010 and replaced by MySQL Workbench. While it allowed executing SQL queries and viewing results, it lacked modern features like schema inspection panels or built-in size reports. Today, MySQL Workbench is the official tool and includes a “Server Status” dashboard that shows database sizes visually. However, for precise control, writing custom queries remains the most reliable method.

Other tools like phpMyAdmin, Adminer, or command-line clients (mysql) also support the same SQL queries. Some tools, like phpMyAdmin, display table and database sizes directly in the interface, but these numbers still come from the same information_schema data. Relying on the query ensures consistency across platforms and avoids UI bugs or display inaccuracies.

Accuracy and Limitations of Size Queries

While the information_schema query is accurate for most cases, it has limitations. It only reflects logical size—the space MySQL believes is used—not physical disk usage. InnoDB tables store data in shared tablespace files (like ibdata1) or file-per-table mode. If using shared tablespaces, dropped tables may not free space immediately, making the actual disk usage larger than the query result.

Additionally, the DATA_LENGTH and INDEX_LENGTH values are updated only when table statistics are refreshed. On large tables with infrequent maintenance, these numbers may be outdated. To force an update, run ANALYZE TABLE table_name; or OPTIMIZE TABLE table_name;, though the latter locks the table and should be used cautiously in production.

Common Problems and Fixes

Several issues can affect size query results:

  • Missing permissions: Users without access to information_schema.TABLES will get empty results. Ensure the MySQL user has the PROCESS or SELECT privilege on system tables.
  • Incorrect size units: Forgetting to divide by 1024 can make results appear in bytes, leading to confusion. Always label output clearly.
  • Overcounting views: Views appear in information_schema.TABLES but have zero size. They don’t affect totals but can appear if filtering isn’t strict.
  • Replication or temporary databases: Some environments auto-create temporary or replication-related schemas. Exclude them explicitly if they skew results.

If the query returns NULL sizes, check that the table engine is supported (MyISAM and InnoDB report sizes; MEMORY tables may not). Also verify that the MySQL server is running and the connection is active.

Alternatives and Command-Line Methods

Besides GUI tools, you can get database sizes using command-line methods. The mysql client allows running the same SQL query in scripts or automation:

mysql -u username -p -e "SELECT TABLE_SCHEMA, ROUND(SUM(DATA_LENGTH + INDEX_LENGTH)/1024/1024,2) AS 'Size (MB)' FROM information_schema.TABLES WHERE TABLE_SCHEMA NOT IN ('information_schema','performance_schema','mysql','sys') GROUP BY TABLE_SCHEMA;"

For physical disk inspection, use shell commands:

  1. Check InnoDB tablespace: ls -lh /var/lib/mysql/ibdata1
  2. List database directories: du -sh /var/lib/mysql/* (shows actual disk use, including logs and temp files)
  3. Compare with logical size to detect discrepancies.

Third-party tools like Percona Toolkit or MySQL Shell offer advanced size analysis, including growth trends and index bloat detection. These are useful for large-scale monitoring but require additional installation.

Frequently Asked Questions

Why does my database size in MySQL differ from file system size?

The SQL query reports logical size from table metadata. File system size includes logs, temporary files, and unallocated space in shared tablespaces. InnoDB’s shared tablespace (ibdata1) can grow but not shrink automatically, causing the file system to show larger usage.

Does the size query include backups or binary logs?

No. The query only sums data and index lengths from active tables. Binary logs, backups, and slow query logs are stored separately and must be checked via file system tools like du or ls.

Can I get table-level size with the same method?

Yes. Remove the GROUP BY clause and add TABLE_NAME to the SELECT list. This shows each table’s size within a database, helping identify large tables or index-heavy ones.

Is MySQL Query Browser still supported?

No. MySQL Query Browser was discontinued over a decade ago. Oracle recommends using MySQL Workbench for GUI access, which includes modern features and active support.

Why are some database sizes showing as NULL?

NULL values usually mean no tables exist in that schema or the user lacks permissions. Check if the database is empty or if the MySQL user has SELECT access on information_schema. Also ensure the database name is spelled correctly in the filter.

How often should I check database size?

For production systems, monitor size weekly or daily using automated scripts. Rapid growth can indicate logging issues, uncontrolled data insertion, or missing cleanup jobs. Set up alerts when size exceeds thresholds.