Logo
Color-Of-Code
  Home   All tags   Terms and Conditions

MySQL queries

March 25, 2019

MySQL

Report table sizes

Replace $DB_NAME with appropriate value.

SELECT
    table_name AS `Table`,
    round(((data_length + index_length) / 1024 / 1024), 2) `Size in MiB`
FROM information_schema.TABLES
WHERE table_schema = "$DB_NAME"
ORDER BY (data_length + index_length) DESC;

Find columns

Replace $DB_NAME, $COLUMN_NAMEi with appropriate values.

SELECT DISTINCT TABLE_NAME
    FROM INFORMATION_SCHEMA.COLUMNS
    WHERE COLUMN_NAME IN ('$COLUMN_NAME1', '$COLUMN_NAME2')
        AND TABLE_SCHEMA='$DB_NAME';