-- Program: my2html.80.sh -- Info: MySQL (8.0) DBA Database SQL report in HTML -- Date: 2018-04-19 -- Version: 1.0.17 (2020-01-14) -- Author: Bartolomeo Bogliolo mail@meo.bogliolo.name -- License: GPL -- -- Notes: -- Init: 1-APR-2006 meo@bogliolo.name -- Initial version -- 1.0.14: 19-APR-2018 -- Production 8.0 script version based on 1.0.13c MySQL 5.7 script -- 1.0.15: 14-FEB-2019 -- Latests versions update -- 1.0.16: 22-JUL-2019 -- Latests versions update -- 1.0.17: 01-JAN-2020 -- Lastest versions update -- -- Usage: mysql --user=$USR --password=$PSS --host=$HST --port=$PRT --force --skip-column-names < my2html.80.sql > $HSTN.$PRT.htm 2> /dev/null USR=root # Careful with security, Eugene!! PSS= HST=127.0.0.1 HSTN=`hostname` PRT=3306 use information_schema; select '

MySQL Database

'; select '

' ; select '

Table of contents:' ; select '


' ; select '

Statistics generated on: ', now(); select ' by: ', user(), 'as: ',current_user(); select 'using: my2html.80.sh v.1.0.17 (2020-01-01)'; select '
Software by '; select 'Meo


'; select '

'; select '

'; select '
Summary
Item', 'Value'; select '
Version :', '', version() union select '
Created :', '', min(create_time) from tables union select '
Started :', '', date_format(date_sub(now(), INTERVAL variable_value second),'%Y-%m-%d %T') from performance_schema.global_status where variable_name='UPTIME' union select '
DB Size (MB):', '', format(sum(data_length+index_length)/(1024*1024),0) from tables union select '
Buffers Size (MB):', '', format(sum(variable_value+0)/(1024*1024),0) from performance_schema.global_variables where lower(variable_name) like '%buffer_size' or lower(variable_name) like '%buffer_pool_size' union select '
Logging Bin. :', '', variable_value from performance_schema.global_status where variable_name='LOG_BIN' union select '
Defined Users :', '', format(count(*),0) from mysql.user union select '
Defined Schemata :', '', count(*) from schemata where schema_name not in ('information_schema') union select '
Defined Tables :', '', format(count(*),0) from tables union select '
Sessions :', '', format(count(*),0) from processlist union select '
Sessions (active) :', '', format(count(*),0) from processlist where command <> 'Sleep' union select '
Questions (#/sec.) :', '', format(g1.variable_value/g2.variable_value,5) from performance_schema.global_status g1, performance_schema.global_status g2 where g1.variable_name='QUESTIONS' and g2.variable_name='UPTIME' union select '
BinLog Writes Day (MB) :', '', format((g1.variable_value*60*60*24)/(g2.variable_value*1024*1024),0) from performance_schema.global_status g1, performance_schema.global_status g2 where g1.variable_name='INNODB_OS_LOG_WRITTEN' and g2.variable_name='UPTIME' union select '
Hostname :', '', variable_value from performance_schema.global_variables where variable_name ='hostname' union select '
Port :', '', variable_value from performance_schema.global_variables where variable_name ='port'; select '


' ; select '

'; select '

' ; select '
Version check
Version', ' Supported', ' Last releases (N or N-1)', ' Last updates (N or N-1)', ' Last update (N) ', ' Notes'; select '
', version(); select ' ', if(SUBSTRING_INDEX(version(),'.',2) in ('8.0','5.7','5.6', '10.4','10.3','10.2','10.1'), 'YES', 'NO') ; -- supported version select ' ', if(SUBSTRING_INDEX(version(),'.',2) in ('8.0','5.7', '10.4','10.3'), 'YES', 'NO') ; -- last2 releases select ' ', if(SUBSTRING_INDEX(version(),'-',1) in ('8.0.17','5.7.27','5.6.44', '10.1.41','10.2.26','10.3.17','10.4.7','5.5.65', '8.0.18','5.7.28','5.6.45', '10.1.42','10.2.27','10.3.18','10.4.8','5.5.66', '8.0.19','5.7.29','5.6.46', '10.1.43','10.2.28','10.3.19','10.4.9','5.5.67'), 'YES', 'NO') ; -- last2 updates (and the next) select ' ', if(SUBSTRING_INDEX(version(),'-',1) in ('8.0.18','5.7.28','5.6.45', '10.1.42','10.2.27','10.3.18','10.4.8','5.5.66', '8.0.19','5.7.29','5.6.46', '10.1.43','10.2.28','10.3.19','10.4.9','5.5.67'), 'YES', 'NO') ; -- last updates (and the next) select 'Last Releases: 8.0.18, 5.7.28, 5.6.46' from dual; -- notes select '
Last Releases (MariaDB): 10.4.11, 10.3.21, 10.2.30, 10.1.43, 5.5.65' from dual; select '

' ; select '

' ; select '
Versions
','MySQL:', variable_value from performance_schema.global_variables where variable_name ='version' union select '
plugin:',plugin_name, plugin_version from plugins union select '
',concat(variable_name, ': '), variable_value from performance_schema.global_variables where variable_name like 'version%' union select '
', 'SYS version:', sys_version from sys.version; select '


' ; select '

' ; select '

' ; select '
Schema/Object Matrix
Database', ' Tables', ' Indexes', ' Routines', ' Triggers', ' Views', ' Primary Keys', ' Foreign Keys', ' All' ; select '
', sk, '', sum(if(otype='T',1,0)), '', sum(if(otype='I',1,0)), '', sum(if(otype='R',1,0)), '', sum(if(otype='E',1,0)), '', sum(if(otype='V',1,0)), '', sum(if(otype='P',1,0)), '', sum(if(otype='F',1,0)), '', count(*) from ( select 'T' otype, table_schema sk, table_name name from tables union select 'I' otype, constraint_schema sk, concat(table_name,'.',constraint_name) name from key_column_usage where ordinal_position=1 union select 'R' otype, routine_schema sk, routine_name name from routines union select 'E' otype, trigger_schema sk, trigger_name name from triggers union select 'V' otype, table_schema sk, table_name name from views union select distinct 'P' otype, CONSTRAINT_SCHEMA sk, TABLE_NAME name from KEY_COLUMN_USAGE where CONSTRAINT_NAME='PRIMARY' union select distinct 'F' otype, CONSTRAINT_SCHEMA sk, concat(TABLE_NAME,'-',CONSTRAINT_NAME) name from KEY_COLUMN_USAGE where REFERENCED_TABLE_NAME is not null ) a group by sk with rollup; select '

' ; select '

' ; select '
Index Types
Type', ' Uniqueness', ' Avg keys', ' Max Keys', ' Count', ' Columns'; select '
', index_type, '', if(non_unique, 'Not Unique', 'UNIQUE'), '', avg(seq_in_index), '', max(seq_in_index), '', count(distinct table_schema,table_name, index_name), '', count(*) from statistics group by index_type, non_unique; select '

' ; select '

' ; select '
Unindexed Tables
Schema ', ' Table ', ' Engine ', ' Estimated rows '; SELECT '
', t.TABLE_SCHEMA, '', t.TABLE_NAME,'', t.ENGINE,'', t.TABLE_ROWS FROM information_schema.TABLES t INNER JOIN information_schema.COLUMNS c ON t.TABLE_SCHEMA=c.TABLE_SCHEMA AND t.TABLE_NAME=c.TABLE_NAME WHERE t.TABLE_SCHEMA NOT IN ('performance_schema','information_schema','mysql','sys') AND t.TABLE_ROWS >100 AND t.TABLE_TYPE in ('BASE TABLE') GROUP BY t.TABLE_SCHEMA,t.TABLE_NAME, t.ENGINE, t.TABLE_ROWS HAVING sum(if(column_key in ('PRI','UNI'), 1,0))=0 ORDER BY 2, 4 limit 100; select '

' ; select '

' ; select '
Orphaned Tables
Table ID', ' Name', ' Flags', ' File Format', ' Row Format'; select '
', TABLE_ID, '', NAME, '', FLAG, '', FILE_FORMAT, '', ROW_FORMAT from INNODB_TABLES where name like "%/#%" limit 100; select '


' ; select '

' ; select '

' ; select '
Space Usage
Database', 'Row#', 'Data size', 'Index size', 'Total size', '', 'MyISAM', 'InnoDB', 'Memory', 'Other Engines', 'Created'; select '
', table_schema, '', format(sum(table_rows),0), '', format(sum(data_length),0), '', format(sum(index_length),0), '', format(sum(data_length+index_length),0), '', '', format(sum((data_length+index_length)* if(engine='MyISAM',1,0)),0), '', format(sum((data_length+index_length)* if(engine='InnoDB',1,0)),0), '', format(sum((data_length+index_length)* if(engine='Memory',1,0)),0), '', format(sum((data_length+index_length)* if(engine='Memory',0,if(engine='MyISAM',0,if(engine='InnoDB',0,1)))),0), '', date_format(min(create_time),'%Y-%m-%d') from tables group by table_schema with rollup; select '


' ; select '

' ; select '

'; select '
Partitioning
Schema', 'Partitioned Tables', 'Partitions' ; select '
', table_schema, '', count(distinct table_name), '', count(*) from information_schema.partitions where partition_name is not null group by table_schema; select '

' ; select '

' ; select '
Partitioning details
Schema', 'Table', 'Method', 'Partitions', 'Subpartitions', 'From partition', 'To partition', 'Est. Rows', 'Size'; select '
', table_schema, '', table_name, '', partition_method, ifnull(subpartition_method,''), '', count(distinct partition_name), '', count(distinct subpartition_name), '', min(partition_name), '', max(partition_name), '', sum(table_rows), '', sum(coalesce(DATA_LENGTH,0)+coalesce(INDEX_LENGTH,0)) from partitions where partition_name is not null group by table_schema, table_name, subpartition_name, partition_method, subpartition_method order by table_schema, table_name, subpartition_name; select '


' ; select '

'; select '

' ; select ''; select '' ; select '
Users
User', 'Host', 'SL IUD CDGRIA CCS CAE RR SSPFSR', 'Select', 'Execute', 'Grant', 'Empty Password', 'Expired', 'Password lifetime', 'Locked'; SELECT '
',user, '', host, '', CONCAT(Select_priv, Lock_tables_priv,' ', Insert_priv, Update_priv, Delete_priv, ' ', Create_priv, Drop_priv, Grant_priv, References_priv, Index_priv, Alter_priv, ' ', Create_tmp_table_priv, Create_view_priv, Show_view_priv, ' ', Create_routine_priv, Alter_routine_priv, Execute_priv, ' ', Repl_slave_priv, Repl_client_priv, ' ', Super_priv, Shutdown_priv, Process_priv, File_priv, Show_db_priv, Reload_priv) AS grt, '', select_priv, '', execute_priv, '', grant_priv, '', if(authentication_string<>'','','NO PWD'), '', password_expired, '', password_lifetime, '', account_locked FROM mysql.user d order by user,host; select '
DB Access
User', 'Host', 'DB', 'Select', 'Execute', 'Grant'; SELECT '
',user, '', host, '', db, '', select_priv, '', execute_priv, '', grant_priv FROM mysql.db d order by user,host; select '

' ; select '

'; select '

' ; select '
Roles
Role NameActive' ; SELECT DISTINCT User, if(from_user is NULL,0, 1) FROM mysql.user LEFT JOIN role_edges ON from_user=user WHERE account_locked='Y' AND password_expired='Y' AND authentication_string=''; select '

' ; select '

'; select '

' ; select '
Virtual Roles
Access LevelUsers' ; select '
Admin' ; select concat(user,'@',host) User from mysql.user where insert_priv='Y' or delete_priv='Y' order by 1; select '
Oper' ; select concat(user,'@',host) from mysql.user where select_priv='Y' and concat(user,'@',host) not in ( select concat(user,'@',host) from mysql.user where insert_priv='Y' or delete_priv='Y') order by 1; select '
Schema Owner' ; select concat(user,'@',host) from mysql.db where create_priv='Y'; select '
CRUD' ; select concat(user,'@',host) from mysql.db where insert_priv='Y' and concat(user,'@',host) not in ( select concat(user,'@',host) from mysql.db where create_priv='Y') order by 1; select '
Read Only' ; select concat(user,'@',host) from mysql.db where select_priv='Y' and concat(user,'@',host) not in ( select concat(user,'@',host) from mysql.db where insert_priv='Y') order by 1; select '
Other' ; select concat(user,'@',host) from mysql.user where concat(user,'@',host) not in ( select concat(user,'@',host) from mysql.db where select_priv='Y') and concat(user,'@',host) not in ( select concat(user,'@',host) from mysql.user where select_priv='Y') order by 1; select '

' ; select '

' ; select '
Users with poor passwords
User', 'Host', 'Password', 'Note'; SELECT '
',user, '', host, '', 'Empty password' FROM mysql.user WHERE authentication_string = ''; SELECT '
',host, '', user, '', authentication_string, 'Same as username' FROM mysql.user WHERE authentication_string = UPPER(CONCAT('*', CAST(SHA1(UNHEX(SHA1(user))) AS CHAR))) OR authentication_string = UPPER(CONCAT('*', CAST(SHA2(UNHEX(SHA2(user,256)),256) AS CHAR))); -- Known hash: root, secret, password, mypass, public, private, 1234, admin, secure, pass, mysql, my123, ... SELECT '
',host, '', user, '', authentication_string, 'Weak password' FROM mysql.user WHERE authentication_string in ('*81F5E21E35407D884A6CD4A731AEBFB6AF209E1B', '*14E65567ABDB5135D0CFD9A70B3032C179A49EE7', '*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19', '*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF4', '*A80082C9E4BB16D9C8E41B0D7EED46126DF4A46E', '*85BB02300F877EB061967510E83F68B1A7325252', '*A4B6157319038724E3560894F7F932C8886EBFCF', '*4ACFE3202A5FF5CF467898FC58AAB1D615029441', '*A36BA850A6E748679226B01E159EF1A7BF946195', '*196BDEDE2AE4F84CA44C47D54D78478C7E2BD7B7', '*E74858DB86EBA20BC33D0AECAE8A8108C56B17FA', '*AF35041D44DF3E88C9F97CC8D3ACAF4695E65B69', UPPER(CONCAT('*', CAST(SHA1(UNHEX(SHA1('prova'))) AS CHAR))), UPPER(CONCAT('*', CAST(SHA1(UNHEX(SHA1('test'))) AS CHAR))), UPPER(CONCAT('*', CAST(SHA1(UNHEX(SHA1('demo'))) AS CHAR))), UPPER(CONCAT('*', CAST(SHA1(UNHEX(SHA1('qwerty'))) AS CHAR))), UPPER(CONCAT('*', CAST(SHA1(UNHEX(SHA1('manager'))) AS CHAR))), UPPER(CONCAT('*', CAST(SHA1(UNHEX(SHA1('supervisor'))) AS CHAR))), UPPER(CONCAT('*', CAST(SHA1(UNHEX(SHA1('toor'))) AS CHAR))), UPPER(CONCAT('*', CAST(SHA1(UNHEX(SHA1('Qwerty'))) AS CHAR))), UPPER(CONCAT('*', CAST(SHA1(UNHEX(SHA1('xxx'))) AS CHAR))), UPPER(CONCAT('*', CAST(SHA1(UNHEX(SHA1('moodle'))) AS CHAR))), UPPER(CONCAT('*', CAST(SHA1(UNHEX(SHA1('drupal'))) AS CHAR))), UPPER(CONCAT('*', CAST(SHA1(UNHEX(SHA1('admin01'))) AS CHAR))), UPPER(CONCAT('*', CAST(SHA1(UNHEX(SHA1('joomla'))) AS CHAR))), UPPER(CONCAT('*', CAST(SHA1(UNHEX(SHA1('wp'))) AS CHAR))), UPPER(CONCAT('*', CAST(SHA1(UNHEX(SHA1('ilikerandompasswords'))) AS CHAR))), UPPER(CONCAT('*', CAST(SHA1(UNHEX(SHA1('changeme'))) AS CHAR))) ); SELECT '
',host, '', user, '', authentication_string, 'Old [pre 4.1] password format' FROM mysql.user WHERE authentication_string not like '*%' AND authentication_string not like '$%' AND authentication_string <> ''; SELECT '
',host, '', user, '', authentication_string, 'Suspected backdoor user' FROM mysql.user WHERE user in ('hanako', 'kisadminnew1', '401hk$', 'guest', 'Huazhongdiguo110'); select '

' ; select '

' ; select '

' ; select '
Suspect SQL Statements
Schema', 'Statement', 'Count'; select '
',SCHEMA_NAME,'', DIGEST_TEXT, '', COUNT_STAR -- FIRST_SEEN, LAST_SEEN from performance_schema.events_statements_summary_by_digest where DIGEST_TEXT like '% OR %? = ?%' or DIGEST_TEXT like '%mysql.user%' limit 20; select '

' ; select '

' ; select '

' ; select '
Spammable tables
Database', 'Object', 'Type', 'Rows', 'MBytes' ; select '
', table_schema, '', table_name, 'T', '', format(table_rows,0), '', format((data_length+index_length)/(1024*1024),0) from tables where (table_name like '%comments' or table_name like '%redirection') and table_rows > 1000 order by table_rows desc; select '


' ; select '

' ; select '

MySQL Memory Usage'; select '
Type', 'Value (MB)' ; select '
Global Caches ', format(sum(variable_value)/(1024*1024),0) from performance_schema.global_variables where lower(variable_name) in ( 'innodb_buffer_pool_size', 'query_cache_size', 'innodb_additional_mem_pool_size', 'innodb_log_file_size', 'innodb_log_buffer_size', 'key_buffer_size', 'table_open_cache', 'tmp_table_size'); select '
Session''s Memory', sum(total_memory_allocated) from sys.user_summary; select '
Estimated Client Alloc. (max conn:', max(g2.variable_value),')', format(sum(g1.variable_value*g2.variable_value)/(1024*1024),0) from performance_schema.global_variables g1, performance_schema.global_status g2 where lower(g1.variable_name) in ( 'binlog_cache_size', 'binlog_stmt_cache_size', 'read_buffer_size', 'read_rnd_buffer_size', 'sort_buffer_size', 'join_buffer_size', 'thread_stack') and lower(g2.variable_name)='max_used_connections'; select '

' ; select '

Performance Schema Memory Footprint'; select '
Total Allocated'; SELECT '
', total_allocated FROM sys.memory_global_total; select '

' ; select '

PS Memory Details'; select '
Event##FreeTotal Alloc.'; select ' Total FreeCurrentMax'; SELECT '
',EVENT_NAME, '',COUNT_ALLOC, '',COUNT_FREE, '',sys.format_bytes(SUM_NUMBER_OF_BYTES_ALLOC), '',sys.format_bytes(SUM_NUMBER_OF_BYTES_FREE), '',sys.format_bytes(CURRENT_NUMBER_OF_BYTES_USED), '',sys.format_bytes(HIGH_NUMBER_OF_BYTES_USED) FROM performance_schema.memory_summary_global_by_event_name WHERE CURRENT_NUMBER_OF_BYTES_USED > 5000000 ORDER BY CURRENT_NUMBER_OF_BYTES_USED DESC; select '

' ; select '


' ; select '

'; select '
Tuning Parameters (most used ones)
Parameter', 'ValueType' ; select '
', variable_name, '', variable_value, 'Cache' from performance_schema.global_variables where lower(variable_name) in ('query_cache_type') union select '
', variable_name, '', variable_value, 'Tuning and timeout' from performance_schema.global_variables where lower(variable_name) in ( 'log_bin', 'slow_query_log') union select '
', variable_name, '', format(variable_value,0), 'Cache' from performance_schema.global_variables where lower(variable_name) in ( 'innodb_buffer_pool_size', 'query_cache_size', 'innodb_additional_mem_pool_size', 'innodb_log_file_size', 'innodb_log_buffer_size', 'key_buffer_size', 'table_open_cache', 'tmp_table_size', 'max_heap_table_size', 'foo') union select '
', variable_name, '', format(variable_value,0), 'Tuning and timeout' from performance_schema.global_variables where lower(variable_name) in ( 'innodb_flush_log_at_trx_commit', 'innodb_flush_log_at_timeout', 'innodb_log_files_in_group', 'innodb_lock_wait_timeout', 'innodb_thread_concurrency', 'skip-external-locking', 'wait_timeout', 'long_query_time', 'sync_binlog', 'foo') union select '
', variable_name, '', format(variable_value,0), 'Client Cache' from performance_schema.global_variables where lower(variable_name) in ( 'binlog_cache_size', 'binlog_stmt_cache_size', 'max_connections', 'read_buffer_size', 'read_rnd_buffer_size', 'sort_buffer_size', 'join_buffer_size', 'thread_stack', 'foo') order by 5, variable_name; select '


' ; select '

' ; select '

'; select '
Engines
Engine', ' Support', ' Comment'; select '
', engine, '', support, '', comment from engines order by support; select '


' ; select '

' ; select '

' ; select '
Per-User Processes
UserCount'; select '
', user, '', count(*) from processlist group by user order by 4 desc; select '
TOTAL (', count(distinct user), ' distinct users)', '', count(*) from processlist; select '
' ; select '
' ; select '
Per-User/Database Processes
UserDatabaseCount'; select '
', user, '', db, '', count(*) from processlist group by user, db order by 6 desc; select '
TOTAL (', count(distinct user,coalesce(db,'')), ' distinct users)', '', count(*) from processlist; select '
' ; select '
' ; select '
Per-Host Processes
HostCount'; select '
', SUBSTRING_INDEX(host,':',1), '', count(*) from processlist group by SUBSTRING_INDEX(host,':',1) order by 4 desc; select '
TOTAL (', count(distinct SUBSTRING_INDEX(host,':',1)), ' distinct hosts)', '', count(*) from processlist; select '
' ; select '

' ; select '
Processes
IdUserHost'; select 'DBCommandTimeState'; select '
',id, '', user, '', host, '', db, '', command, '', time, '', state from processlist order by id; select '

' ; select '

' ; select '

' ; select '
Running SQL
IdUserTime'; select 'StateInfo'; select '
',id, '', user, '', time, '', state, '', substr(replace(replace(info,'<','<'),'>','>'),1,2024) from processlist where command <> 'Sleep' order by id; select '


' ; select '

' ; select '

InnoDB Statistics
' ; select '

' ; select '
Transactions
IdTRX IdStateStarted'; select 'WeightReq. lockQueryOperationIsolation'; select '
',trx_mysql_thread_id, '',trx_id, '',trx_state, '',trx_started, '',trx_weight, '',trx_requested_lock_id, '',trx_query, '',trx_operation_state, '',trx_isolation_level from INFORMATION_SCHEMA.innodb_trx; select '
' ; select '

' ; select '

' ; select '
Waiting Locks
TRX IdLock IdBlocking TRXBlocking Lock'; select '
',requesting_trx_id, '',requested_lock_id, '',blocking_trx_id, '',blocking_lock_id from INFORMATION_SCHEMA.INNODB_LOCK_WAITS; select '
' ; select '

' ; select '
Locks
TRX IdLock IdModeType'; select 'TableIndex'; select '
',lock_trx_id, '',lock_id, '',lock_mode, '',lock_type, '',lock_table, '',lock_index from INFORMATION_SCHEMA.INNODB_LOCKS; select '
' ; select '

' ; select '
Pool Statistics
Pool IdSizeFree buffersDatabase pages'; select 'Old pagesModified pagesPages readPages created'; select 'Pages writtenHit rate'; select '
',POOL_ID, '',POOL_SIZE, '',FREE_BUFFERS, '',DATABASE_PAGES, '',OLD_DATABASE_PAGES, '',MODIFIED_DATABASE_PAGES, '',NUMBER_PAGES_READ, '',NUMBER_PAGES_CREATED, '',NUMBER_PAGES_WRITTEN, '',HIT_RATE from INFORMATION_SCHEMA.INNODB_BUFFER_POOL_STATS; select '

' ; select '

' ; select '
Tablespaces
Tablespace TypeFile FormatRow FormatTables', 'Columns'; SELECT '
',if(SPACE=0,'System','FilePerTable') TBS,'',FILE_FORMAT,'', ROW_FORMAT,'', count(*) TABS,'', sum(N_COLS-3) COLS FROM INFORMATION_SCHEMA.INNODB_SYS_TABLES group by FILE_FORMAT, ROW_FORMAT, if(SPACE=0,'System','FilePerTable'); select '


' ; select '

' ; select '

' ; select '
Performance Statistics Summary
StatisticValueSuggested valuePotential Action'; select '
', variable_name, ' (days)', round(variable_value/(3600*24),1), '', '' from performance_schema.global_status where variable_name='UPTIME' union select '
', 'Buffer Cache: MyISAM Read Hit Ratio', '', format(100-t1.variable_value*100/t2.variable_value,2), ' >95', 'Increase KEY_BUFFER_SIZE' from performance_schema.global_status t1, performance_schema.global_status t2 where t1.variable_name='KEY_READS' and t2.variable_name='KEY_READ_REQUESTS' union select '
', 'Buffer Cache: InnoDB Read Hit Ratio', '', format(100-t1.variable_value*100/t2.variable_value,2), ' >95', 'Increase INNODB_BUFFER_SIZE' from performance_schema.global_status t1, performance_schema.global_status t2 where t1.variable_name='INNODB_BUFFER_POOL_READS' and t2.variable_name='INNODB_BUFFER_POOL_READ_REQUESTS' union select '
', 'Buffer Cache: MyISAM Write Hit Ratio', '', format(100-t1.variable_value*100/t2.variable_value,2), ' >95', 'Increase KEY_BUFFER_SIZE' from performance_schema.global_status t1, performance_schema.global_status t2 where t1.variable_name='KEY_WRITES' and t2.variable_name='KEY_WRITE_REQUESTS' union select '
', 'Log Cache: InnoDB Log Write Ratio', '', format(100-t1.variable_value*100/t2.variable_value,2), ' >95', 'Increase INNODB_LOG_BUFFER_SIZE' from performance_schema.global_status t1, performance_schema.global_status t2 where t1.variable_name='INNODB_LOG_WRITES' and t2.variable_name='INNODB_LOG_WRITE_REQUESTS' union select '
', 'Query Cache: Efficiency (Hit/Select)', '', format(t1.variable_value*100/(t1.variable_value+t2.count_star),2), ' >30', '' from performance_schema.global_status t1, performance_schema.events_statements_summary_global_by_event_name t2 where t1.variable_name='QCACHE_HITS' and t2.event_name='statement/sql/select' union select '
', 'Query Cache: Hit ratio (Hit/Query Insert)', '', format(t1.variable_value*100/(t1.variable_value+t2.variable_value),2), ' >80', '' from performance_schema.global_status t1, performance_schema.global_status t2 where t1.variable_name='QCACHE_HITS' and t2.variable_name='QCACHE_INSERTS' union select '
', s.variable_name, '', concat(s.variable_value, ' /', v.variable_value), 'Far from maximum', 'Increase MAX_CONNECTIONS' from performance_schema.global_status s, performance_schema.global_variables v where s.variable_name='THREADS_CONNECTED' and v.variable_name='MAX_CONNECTIONS' union select '
', variable_name, '', variable_value, 'LOW', 'Check user load' from performance_schema.global_status where variable_name='THREADS_RUNNING' union select '
', variable_name, '', format(variable_value,0), 'LOW', 'Check application' from performance_schema.global_status where variable_name='SLOW_QUERIES' union select '
', g1.variable_name, ' #/sec.', format(g1.variable_value/g2.variable_value,5), '', '' from performance_schema.global_status g1, performance_schema.global_status g2 where g1.variable_name='QUESTIONS' and g2.variable_name='UPTIME' union select '
', 'SELECT', ' #/sec.', format(g1.count_star/g2.variable_value,5), '', '' from performance_schema.events_statements_summary_global_by_event_name g1, performance_schema.global_status g2 where g1.EVENT_NAME = 'statement/sql/select' and g2.variable_name='UPTIME' union select '
', 'COMMIT', ' #/sec. (TPS)', format(g1.count_star/g2.variable_value,5), '', '' from performance_schema.events_statements_summary_global_by_event_name g1, performance_schema.global_status g2 where g1.EVENT_NAME = 'statement/sql/commit' and g2.variable_name='UPTIME' union select '
', g1.variable_name, ' #/sec.', format(g1.variable_value/g2.variable_value,5), '', '' from performance_schema.global_status g1, performance_schema.global_status g2 where g1.variable_name='CONNECTIONS' and g2.variable_name='UPTIME' union select '
','COM DML #/sec.','', format((g2.count_star+g3.count_star+g4.count_star+g5.count_star+g6.count_star +g7.count_star+g8.count_star+g9.count_star)/g1.variable_value,5), '', '' from performance_schema.global_status g1, performance_schema.events_statements_summary_global_by_event_name g2, performance_schema.events_statements_summary_global_by_event_name g3, performance_schema.events_statements_summary_global_by_event_name g4, performance_schema.events_statements_summary_global_by_event_name g5, performance_schema.events_statements_summary_global_by_event_name g6, performance_schema.events_statements_summary_global_by_event_name g7, performance_schema.events_statements_summary_global_by_event_name g8, performance_schema.events_statements_summary_global_by_event_name g9 where g1.variable_name='UPTIME' and g2.event_name='statement/sql/insert' and g3.event_name ='statement/sql/update' and g4.event_name ='statement/sql/delete' and g5.event_name ='statement/sql/select' and g6.event_name ='statement/sql/update_multi' and g7.event_name ='statement/sql/delete_multi' and g8.event_name ='statement/sql/replace' and g9.event_name ='statement/sql/replace_select' union select '
', g1.variable_name, ' Mb/sec.', format(g1.variable_value*8/(g2.variable_value*1024*1024),5), '', '' from performance_schema.global_status g1, performance_schema.global_status g2 where g1.variable_name='BYTES_SENT' and g2.variable_name='UPTIME' union select '
', g1.variable_name, ' Mb/sec.', format(g1.variable_value*8/(g2.variable_value*1024*1024),5), '', '' from performance_schema.global_status g1, performance_schema.global_status g2 where g1.variable_name='BYTES_RECEIVED' and g2.variable_name='UPTIME' union select '
', 'DBcpu (SUM_TIMER_WAIT)', '', format((sum(SUM_TIMER_WAIT)/1000000000000)/variable_value, 5), '', '' from performance_schema.global_status, performance_schema.events_statements_summary_global_by_event_name where variable_name='UPTIME' group by variable_value order by 1; select '

' ; select '
Performance Advice
Expert suggestions onValueAction to correct'; select '
', g1.variable_name, ' #/hour', format((g1.variable_value*60*60)/g2.variable_value,5), '', 'Increase TABLE_OPEN_CACHE' from performance_schema.global_status g1, performance_schema.global_status g2 where g1.variable_name='OPENED_TABLES' and g2.variable_name='UPTIME' and g1.variable_value*60*60/g2.variable_value>12 union select '
', g1.variable_name, ' #/hour', format((g1.variable_value*60*60)/g2.variable_value,5), '', 'Increase SORT_BUFFER_SIZE' from performance_schema.global_status g1, performance_schema.global_status g2 where g1.variable_name='SORT_MERGE_PASSES' and g2.variable_name='UPTIME' and g1.variable_value*60*60/g2.variable_value>12 union select '
', g1.variable_name, ' %', format(g1.variable_value*100/(g1.variable_value+g2.variable_value),5), '', 'Increase MAX_HEAP_TABLE_SIZE and TMP_TABLE_SIZE' from performance_schema.global_status g1, performance_schema.global_status g2 where g1.variable_name='CREATED_TMP_DISK_TABLES' and g2.variable_name='CREATED_TMP_TABLES' and g1.variable_value/g2.variable_value>0.1 union select '
', g1.variable_name, ' %', format(g1.variable_value*100/(g2.variable_value),5), '', 'Increase BINLOG_CACHE_SIZE' from performance_schema.global_status g1, performance_schema.global_status g2 where g1.variable_name='BINLOG_CACHE_DISK_USE' and g2.variable_name='BINLOG_CACHE_USE' and g1.variable_value/g2.variable_value>0.2 union select '
', g1.variable_name, ' #/hour', format((g1.variable_value*60*60)/g2.variable_value,5), '', 'Increase INNODB_LOG_BUFFER_SIZE' from performance_schema.global_status g1, performance_schema.global_status g2 where g1.variable_name='INNODB_LOG_WAITS' and g2.variable_name='UPTIME' and g1.variable_value*60*60/g2.variable_value>1 union select '
', g1.variable_name, ' MB/hour', format((g1.variable_value*60*60)/(g2.variable_value*1024*1024),5), '', 'Tune INNODB_LOG_FILE_SIZE' from performance_schema.global_status g1, performance_schema.global_status g2 where g1.variable_name='INNODB_OS_LOG_WRITTEN' and g2.variable_name='UPTIME' and (g1.variable_value*60*60)/(g2.variable_value*1024*1024)>5 order by 1; select '

' ; select '

' ; select '

Uptime', truncate(variable_value/(3600*24),0), 'days ', SEC_TO_TIME(mod(variable_value, 3600*24)), '
' from performance_schema.global_status where variable_name='UPTIME'; select '

' ; select '
Statement Events
Event', 'Count','Sum Timer','Human Timer'; select '
',EVENT_NAME, '',COUNT_STAR, '',SUM_TIMER_WAIT, '', SEC_TO_TIME(SUM_TIMER_WAIT/1000000000000) from performance_schema.events_statements_summary_global_by_event_name where count_star > 0 order by SUM_TIMER_WAIT desc limit 10; select '

'; select '

' ; select '
Wait Events
Event', 'Count','Sum Timer','Human Timer'; select '
',EVENT_NAME, '',COUNT_STAR, '',SUM_TIMER_WAIT, '', SEC_TO_TIME(SUM_TIMER_WAIT/1000000000000) from performance_schema.events_waits_summary_global_by_event_name where count_star > 0 and event_name != 'idle' order by SUM_TIMER_WAIT desc limit 10; select '

'; select '

' ; select '
Lock Wait
Type','Schema','Name', 'Count','Sum Timer','Human Timer'; select '
',OBJECT_TYPE, '', OBJECT_SCHEMA, '', OBJECT_NAME, '', COUNT_STAR, '', SUM_TIMER_WAIT, '', SEC_TO_TIME(SUM_TIMER_WAIT/1000000000000) from performance_schema.table_lock_waits_summary_by_table where count_star > 0 order by SUM_TIMER_WAIT desc limit 10; select '

'; select '

' ; select '
File events
Event', 'Count','Sum Timer','Human Timer'; select '
',EVENT_NAME,'',COUNT_STAR,'',SUM_TIMER_WAIT, '', SEC_TO_TIME(SUM_TIMER_WAIT/1000000000000) from performance_schema.file_summary_by_event_name order by SUM_TIMER_WAIT desc limit 10; select '

'; select '

' ; select '
File access
File Name','Event Name', 'Count','Sum Timer','Human Timer', '#Read','Timer Read','Byte Read', '#Write','Timer Write','Byte Write'; select '
',FILE_NAME,'',EVENT_NAME,'',COUNT_STAR,'',SUM_TIMER_WAIT,'', SEC_TO_TIME(SUM_TIMER_WAIT/1000000000000),'', COUNT_READ,'',SUM_TIMER_READ,'',SUM_NUMBER_OF_BYTES_READ,'', COUNT_WRITE,'',SUM_TIMER_WRITE,'',SUM_NUMBER_OF_BYTES_WRITE from performance_schema.file_summary_by_instance order by SUM_TIMER_WAIT desc limit 10; select '

'; select '

' ; select '
SQL StatementsRepresentativeness:', round((1-sum(if(digest is null, count_star,0))/sum(count_star))*100,2), '%' from performance_schema.events_statements_summary_by_digest; select '
Schema','Text', 'Count','Sum Timer','Human Timer','Average (sec.)', 'Rows affected','Rows Sent','Rows Examined', 'TMP Disk Create','TMP Create', 'Sort Merge#','No Index','No Good Index'; select '
',SCHEMA_NAME,'',DIGEST_TEXT,'',COUNT_STAR,'', SUM_TIMER_WAIT,'',SEC_TO_TIME(SUM_TIMER_WAIT/1000000000000),'', round(AVG_TIMER_WAIT/1000000000000,3) AVG_TIMER_WAIT,'', SUM_ROWS_AFFECTED,'',SUM_ROWS_SENT,'',SUM_ROWS_EXAMINED,'', SUM_CREATED_TMP_DISK_TABLES,'',SUM_CREATED_TMP_TABLES,'',SUM_SORT_MERGE_PASSES,'', SUM_NO_INDEX_USED,'',SUM_NO_GOOD_INDEX_USED from performance_schema.events_statements_summary_by_digest order by SUM_TIMER_WAIT desc limit 20; select '

'; select '

Slowest Statements' ; select '
Schema','Text', 'Count','Sum Timer','Human Timer','Average (sec.)', 'Rows affected','Rows Sent','Rows Examined', 'TMP Disk Create','TMP Create', 'Sort Merge#','No Index','No Good Index'; select '
',SCHEMA_NAME,'',DIGEST_TEXT,'',COUNT_STAR,'', SUM_TIMER_WAIT,'',SEC_TO_TIME(SUM_TIMER_WAIT/1000000000000),'', round(AVG_TIMER_WAIT/1000000000000,3) AVG_TIMER_WAIT,'', SUM_ROWS_AFFECTED,'',SUM_ROWS_SENT,'',SUM_ROWS_EXAMINED,'', SUM_CREATED_TMP_DISK_TABLES,'',SUM_CREATED_TMP_TABLES,'',SUM_SORT_MERGE_PASSES,'', SUM_NO_INDEX_USED,'',SUM_NO_GOOD_INDEX_USED from performance_schema.events_statements_summary_by_digest order by AVG_TIMER_WAIT desc limit 5; select '

'; select '

' ; select '
Consumers
Name', 'Enabled'; select '
', NAME, '',ENABLED from performance_schema.setup_consumers order by enabled, name; select '


'; select '

' ; select '

' ; select '
Biggest Objects
Database', 'Object', 'Type', 'Engine', 'Bytes', 'Est. rows'; select '
', table_schema, '', table_name, 'T','',engine, '', format(data_length+index_length,0), '', format(table_rows,0) from tables order by data_length+index_length desc limit 32; select '


' ; select '

' ; select '

' ; select '
Host Connections
Host', 'Current Connections', 'Total Connections'; select '
',HOST, '', CURRENT_CONNECTIONS, '', TOTAL_CONNECTIONS from performance_schema.hosts order by CURRENT_CONNECTIONS desc, TOTAL_CONNECTIONS desc; select '
TOTAL HOSTS:',count(distinct HOST), '', sum(CURRENT_CONNECTIONS), '', sum(TOTAL_CONNECTIONS) from performance_schema.hosts; select '

' ; select '

' ; select '
Host Cache
Host', 'IP', 'Validated', 'SUM Errors', 'First Seen', 'Last Seen', 'Last Error Seen', '# Handshake Err.', '# Authentication Err.', '# ACL Err.' ; select '
', host, '', ip, '', host_validated, '', SUM_CONNECT_ERRORS ERR, '', FIRST_SEEN, '', LAST_SEEN, '', LAST_ERROR_SEEN, '', COUNT_HANDSHAKE_ERRORS, '', COUNT_AUTHENTICATION_ERRORS, '', COUNT_HOST_ACL_ERRORS from performance_schema.host_cache; select '

' ; select '

Max Connect Errors ', @@global.max_connect_errors; select '


' ; select '

' ; select '

' ; select '
Replication
Master' ;
show master status;
SHOW VARIABLES LIKE 'rpl_semi_sync_master_%';
SHOW STATUS LIKE 'rpl_semi_sync_master_status';
select '

' ; show binary logs; select '

Slave' ;
SHOW VARIABLES LIKE 'rpl_semi_sync_slave_enabled';
SHOW STATUS LIKE 'rpl_semi_sync_slave_status';
select '

' ; select '

' ; select '
Slave Connection configuration
CHANNEL NAME ', ' MASTER HOST', ' PORT ', ' USER ', ' AUTO POSITION ', ' SSL ', ' HEARTBEAT_INTERVAL'; select '
',CHANNEL_NAME, '',HOST, '',PORT, '',USER, '',AUTO_POSITION, '',SSL_ALLOWED, '',HEARTBEAT_INTERVAL from performance_schema.replication_connection_configuration; select '

' ; select '

' ; select '
Connection status
CHANNEL NAME ', ' GROUP NAME', ' SOURCE UUID ', ' THREAD ID ', ' SERVICE STATE ', ' RECEIVED HEARTBEATS ', ' LAST HEARTBEAT ', ' RECEIVED TRANSACTION SET ', ' LAST_ERROR NUMBER ', ' LAST_ERROR MESSAGE ', ' LAST_ERROR TIMESTAMP'; select '
',CHANNEL_NAME, '',GROUP_NAME, '',SOURCE_UUID, '',THREAD_ID, '',SERVICE_STATE, '',COUNT_RECEIVED_HEARTBEATS, '',LAST_HEARTBEAT_TIMESTAMP, '',RECEIVED_TRANSACTION_SET, '',LAST_ERROR_NUMBER, '',LAST_ERROR_MESSAGE, '',LAST_ERROR_TIMESTAMP from performance_schema.replication_connection_status; select '

' ; select '

' ; select '
Applier Status
CHANNEL NAME ', ' THREAD_ID ', ' SERVICE_STATE ', ' LAST_ERROR NUMBER ', ' LAST_ERROR MESSAGE ', ' LAST_ERROR TIMESTAMP '; select '
',CHANNEL_NAME, '',THREAD_ID, '',SERVICE_STATE, '',LAST_ERROR_NUMBER, '',LAST_ERROR_MESSAGE, '',LAST_ERROR_TIMESTAMP from performance_schema.replication_applier_status_by_coordinator; select '

' ; select '

' ; select '
Applier Status by worker
CHANNEL NAME ', ' WORKER_ID ', ' THREAD_ID ', ' SERVICE_STATE ', ' LAST_SEEN_TRANSACTION ', ' LAST_ERROR NUMBER ', ' LAST_ERROR MESSAGE ', ' LAST_ERROR TIMESTAMP '; select '
',CHANNEL_NAME, '',WORKER_ID, '',THREAD_ID, '',SERVICE_STATE, '',LAST_SEEN_TRANSACTION, '',LAST_ERROR_NUMBER, '',LAST_ERROR_MESSAGE, '',LAST_ERROR_TIMESTAMP from performance_schema.replication_applier_status_by_worker; select '

' ; select '

' ; select '
Group Replication/InnoDB Cluster
MEMBER_HOST ', ' MEMBER_PORT ', ' MEMBER_ID ', ' MEMBER_STATE '; select '
', MEMBER_HOST, '',MEMBER_PORT, '',MEMBER_ID, '',MEMBER_STATE from performance_schema.replication_group_members; select '

' ; select '

' ; SELECT '
Primary Member
', VARIABLE_VALUE, '', member_host, ':', member_port FROM performance_schema.global_status JOIN performance_schema.replication_group_members WHERE VARIABLE_NAME= 'group_replication_primary_member' AND member_id=variable_value; select '

' ; select '


' ; select '

' ; select '

' ; select '
Stored Routines
Schema', 'Type', 'Objects' ; select '
',routine_schema, '', routine_type, '', count(*) from routines group by routine_schema, routine_type; select '


' ; select '

' ; select '

' ; select '
Data types
Schema', 'Data Type', 'Count(*)'; select '
',table_schema, '', data_type, '', count(*) from columns where table_schema not in ('mysql', 'performance_schema', 'information_schema', 'sys') group by table_schema, data_type order by table_schema, data_type; select '


' ; select '

' ; select '

' ; select '
Scheduler
', variable_value from performance_schema.global_variables where variable_name='EVENT_SCHEDULER'; select '

' ; select '

' ; select '
Scheduled Jobs
Event', 'Status', 'Type', 'Schedule', 'Command'; select '
',concat(event_schema,'.',event_name), '', status, '', event_type, '', ifnull(execute_at,''), ifnull(interval_value,''),ifnull(interval_field,''), '', event_definition from events; select '


' ; select '

' ; select '

'; select '
NLS
Schema','DEFAULT CHARACTER_SET_NAME','DEFAULT COLLATION_NAME'; SELECT '
',schema_name, '', DEFAULT_CHARACTER_SET_NAME, '', DEFAULT_COLLATION_NAME FROM information_schema.SCHEMATA where schema_name not in ('mysql', 'information_schema', 'sys', 'performance_schema', 'test', 'tmpdir') and schema_name not like '%lost+found' order by schema_name; select '

' ; select '

'; select '
NLS: Columns
Schema','CHARACTER_SET_NAME','COLLATION_NAME','Count'; SELECT '
',table_schema, '', CHARACTER_SET_NAME, '', COLLATION_NAME, '', count(*) FROM information_schema.COLUMNS where table_schema not in ('mysql', 'information_schema', 'sys', 'performance_schema', 'test') and CHARACTER_SET_NAME is not null group by table_schema, CHARACTER_SET_NAME, COLLATION_NAME union SELECT '
', 'TOTAL', '', CHARACTER_SET_NAME, '', COLLATION_NAME, '', count(*) FROM information_schema.COLUMNS where table_schema not in ('mysql', 'information_schema', 'sys', 'performance_schema', 'test') and CHARACTER_SET_NAME is not null group by CHARACTER_SET_NAME , COLLATION_NAME; select '

' ; select '

'; select '
NLS: Parameters
Parameter', 'Value' ; select '
', variable_name, '', replace(variable_value,',',', ') from performance_schema.global_variables where variable_name like 'character_set_%' or variable_name like 'collation_%' order by variable_name; select '


' ; select '

' ; select '

'; select '
MySQL Parameters
Parameter', 'Value' ; select '
', variable_name, '', replace(variable_value,',',', ') from performance_schema.global_variables where variable_name<>'server_audit_loc_info' order by variable_name; select '


' ; select '

' ; select '

'; select '
MySQL Global Status
Statistic', 'Value' ; select '
', variable_name, '', variable_value from performance_schema.global_status order by variable_name; select '


' ; select '

Statistics generated on: ', now(); select '

For more info on my2html contact' ; select 'Meo Bogliolo.

' ;