This only works if you’re using innodb_file_per_table.
Purpose: import this csv quickly into google sheets (or other
spreadsheet) and compare MySQL’s internal data size to the
container size on disk to determine tables needing to be
optimized (or “null altered”) to reclaim disk space and maybe
increase performance due to defragmentation. Rule of thumb is
probably something like >=10% difference may warrant action.
I wrote this loop as a one-liner dynamically / ad-hoc on the
command line a couple weeks ago but made it into a configurable,
yet quick-and-dirty shell script, below.
Add -u and -p arguments to MySQL CLI command if you need to, or
just place a .my.cnf in your home directory and use the script
as-is.
#!/bin/bash
DATADIR="/path/to/datadir" # ex: /var/lib/mysql
SCHEMANAME="yourschema"
for x in `mysql --batch -n -e "select concat(concat(table_name,'.ibd'),',',(data_length + index_length)) as …
[Read more]