SQLNirvana by Pyro

Free tools › MySQL health & tuning check

MySQL health & tuning check

Run one read-only query, paste the result, and get a score with the settings to change. No sign-up, nothing stored.

1 Run this read-only query

Option A: command line
mysql -u root -p -N -B -r < sqlnirvana-check.sql > sqlnirvana-check.json
Option B: paste into your SQL clientDownload .sql
-- SQLNirvana free check for MySQL 8.0 / 8.4 / 9.x (read-only: it only SELECTs settings, counters and table metadata).
-- Run as an admin user:  mysql -u root -p -N -B -r < sqlnirvana-check.sql > sqlnirvana-check.json
SELECT JSON_OBJECT(
  'tool', 'sqlnirvana-check', 'engine', 'mysql',
  'variables', (SELECT JSON_OBJECTAGG(LOWER(VARIABLE_NAME), VARIABLE_VALUE) FROM performance_schema.global_variables),
  'status', (SELECT JSON_OBJECTAGG(LOWER(VARIABLE_NAME), VARIABLE_VALUE) FROM performance_schema.global_status),
  'users', (SELECT JSON_ARRAYAGG(JSON_OBJECT('user', User, 'host', Host, 'plugin', plugin,
        'empty_password', authentication_string = '', 'super_priv', Super_priv = 'Y', 'locked', account_locked = 'Y',
        'ssl_type', ssl_type)) FROM mysql.user),
  'tables', (SELECT JSON_ARRAYAGG(JSON_OBJECT('schema', t.TABLE_SCHEMA, 'name', t.TABLE_NAME, 'engine', t.ENGINE,
        'rows', t.TABLE_ROWS, 'data_length', t.DATA_LENGTH, 'index_length', t.INDEX_LENGTH, 'data_free', t.DATA_FREE,
        'collation', t.TABLE_COLLATION, 'auto_increment', t.AUTO_INCREMENT))
      FROM information_schema.TABLES t
      WHERE t.TABLE_TYPE = 'BASE TABLE' AND t.TABLE_SCHEMA NOT IN ('mysql','sys','performance_schema','information_schema')),
  'primary_keys', (SELECT JSON_ARRAYAGG(CONCAT(TABLE_SCHEMA, '.', TABLE_NAME)) FROM information_schema.TABLE_CONSTRAINTS
      WHERE CONSTRAINT_TYPE = 'PRIMARY KEY' AND TABLE_SCHEMA NOT IN ('mysql','sys','performance_schema','information_schema')),
  'indexes', (SELECT JSON_ARRAYAGG(JSON_OBJECT('schema', s.TABLE_SCHEMA, 'table', s.TABLE_NAME, 'name', s.INDEX_NAME,
        'unique', s.NON_UNIQUE = 0, 'columns', s.cols))
      FROM (SELECT TABLE_SCHEMA, TABLE_NAME, INDEX_NAME, MIN(NON_UNIQUE) AS NON_UNIQUE,
                   GROUP_CONCAT(COLUMN_NAME ORDER BY SEQ_IN_INDEX SEPARATOR ',') AS cols
            FROM information_schema.STATISTICS
            WHERE TABLE_SCHEMA NOT IN ('mysql','sys','performance_schema','information_schema')
            GROUP BY TABLE_SCHEMA, TABLE_NAME, INDEX_NAME) s),
  'auto_increment_columns', (SELECT JSON_ARRAYAGG(JSON_OBJECT('schema', TABLE_SCHEMA, 'table', TABLE_NAME, 'column', COLUMN_NAME,
        'type', COLUMN_TYPE))
      FROM information_schema.COLUMNS WHERE EXTRA LIKE '%auto_increment%'
        AND TABLE_SCHEMA NOT IN ('mysql','sys','performance_schema','information_schema'))
) AS sqlnirvana_check;

Needs a user that can read performance_schema, information_schema and mysql.user (any admin user). It does not read table rows, and it changes nothing.

2 Paste the result

Analysed in memory and thrown away. We only count how many checks run.