SxSQLyze: StackX SQL Analyzer
SxSQLyze 1.3 is a GPL-licensed Bash script that quickly provides an operational view of a MariaDB or MySQL instance: database and table sizes, fragmentation, engines, collations, indexes and estimated growth.
It now prefers the mariadb client and falls back to mysql when that is the only one available. Help and version information can be displayed without opening a SQL connection. Database names, numbers and units are validated before use.
Available analyses
--databases: size of every user database.
--tables <database>: table sizes in one database.
--top <N>: the N largest tables in the instance.
--growth-hint <database>: indicative daily growth estimate.
--engine-stats <database>: storage-engine distribution.
--table-fragmentation <database>: space reported as reclaimable through data_free.
--charset-collation <database>: table collations.
--index-usage <database>: index size by table.
--analyze-all: runs the size, engine, fragmentation, collation and index analyses across every user database.
--unit mb|gb: selects the output unit, with GB as the default.
Installation and examples
cp sxsqlyze.sh /usr/local/bin/sxsqlyze
chmod +x /usr/local/bin/sxsqlyze
sxsqlyze --databases
sxsqlyze --tables production --unit mb
sxsqlyze --top 20
sxsqlyze --table-fragmentation production
sxsqlyze --index-usage production --unit gb
sxsqlyze --analyze-all
The SQL client must already be able to connect, for example through root socket authentication or a protected local client configuration file. SxSQLyze neither asks for nor carries a password on its command line.
Interpreting the results
The growth estimate relies on metadata available from information_schema. It is an operational hint, not a time machine. Likewise, data_free gives an indication of fragmentation or reusable space; on its own, it is not a reason to perform an intrusive operation on a production database.
Resources
Script: sxsqlyze.sh
—
Christophe Casalegno (find all my links on all.bo)