dataiotech Labs
dbaguidedbaguideDBAdataxtoolsdataopsphere
Scripts Library/mysql/#27
Script #27
mysql
Monitoringread-onlyMin Version: 5.7

MySQL InnoDB Buffer Pool Hit Ratio

Compares buffer pool read requests against disk reads to compute the hit ratio. Tells you whether memory sizing is sufficient.

#innodb#buffer-pool#cache-hit
mysql · sql
SELECT
  (SELECT variable_value FROM performance_schema.global_status WHERE variable_name='Innodb_buffer_pool_read_requests') AS read_requests,
  (SELECT variable_value FROM performance_schema.global_status WHERE variable_name='Innodb_buffer_pool_reads')         AS disk_reads,
  ROUND(100 * (1 -
    (SELECT variable_value FROM performance_schema.global_status WHERE variable_name='Innodb_buffer_pool_reads') /
    NULLIF((SELECT variable_value FROM performance_schema.global_status WHERE variable_name='Innodb_buffer_pool_read_requests'), 0)
  ), 3) AS hit_ratio_pct;
Operational Notes & Remediation Guidance

Target is 99%+ in OLTP environments. Lower ratios indicate memory pressure or poorly indexed queries evicting hot pages.

Production Safety & Execution Standards
  • This script is designed for read-only diagnostics; it does not alter schema or modify data directly.
  • Prior to executing on production systems under high load, verify the target database version (Min. Version: 5.7).
  • Exercise caution with mutating actions (e.g., terminating sessions or dropping indexes) referenced in the notes section.