Hosting Operations
Show MySQL Database Sizes
Disk usage is rising and you need to know which MySQL schemas are largest.
Command
mysql -e "select table_schema, round(sum(data_length + index_length)/1024/1024, 1) as mb from information_schema.tables group by table_schema order by mb desc;"
What changed
Nothing changes. MySQL prints schema sizes.
Danger
safe
When to use it
Use when storage alerts fire, backups grow, or migrations unexpectedly increase disk usage.
When not to use it
Do not use schema size alone to identify the exact table or index growth source.
Undo or recovery
No undo needed because this command is read-only.
Expected output
A sorted list of schema names and approximate size in MiB.
demo script
Disposable terminal steps
df -h /var/lib/mysqlmysql -e "select table_schema, round(sum(data_length + index_length)/1024/1024, 1) as mb from information_schema.tables group by table_schema order by mb desc;"mysql -e "show databases;"
simulated output
What it looks like
::fixture-ready::
$ df -h /var/lib/mysql
Filesystem Size Used Avail Use% Mounted on
/dev/vdb1 80G 59G 17G 78% /var/lib/mysql
::exit-code::0
$ mysql -e "select table_schema, round(sum(data_length + index_length)/1024/1024, 1) as mb from information_schema.tables group by table_schema order by mb desc;"
table_schema mb
shop 512.4
analytics 240.8
mysql 18.2
::exit-code::0
$ mysql -e "show databases;"
Database
analytics
information_schema
mysql
shop
::exit-code::0
YouTube Short
Find the biggest MySQL schema.
When MySQL storage grows, get the schema-level view before drilling into individual tables.
LinkedIn hook
The storage alert needed a database name.
Question: When MySQL disk usage grows, do you check schema sizes first?
experiments
A/B tests to run
Metric: linkedin_click_through_rate
A: The storage alert needed a database name.
B: Find the largest MySQL schema first.