-- Program: my2html.103.sh
-- MariaDB (10.3+) DBA Database SQL report in HTML
-- Date: 2015-01-01
-- 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.13.mar: 1-APR-2018
-- First MariaDB script based on MySQL one
-- 1.0.14: 31-OCT-2018
-- Lastest versions update
-- 1.0.15: 14-FEB-2019
-- Lastest versions update
-- 1.0.16: 22-JUL-2019
-- Lastest versions update
-- 1.0.17: 01-JAN-2020
-- Lastest versions update, SQL scripts for different MySQL/MariaDB, (a) little bugs in users
--
-- Usage: mysql --user=$USR --password=$PSS --host=$HST --port=$PRT --force --skip-column-names < my2html.103.sql > $HSTN.$PRT.htm 2> /dev/null
use information_schema;
select '
Statistics generated on: ', now();
select ' by: ', user(), 'as: ',current_user();
select 'using: my2html.103.sql v.1.0.17 (2020-01-14)';
select '
Software by ';
select 'Meo
Summary |
';
select '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 global_status
where variable_name='UPTIME'
union
select ' |
DB Size (MB):',
' | ',
format(sum(data_length+index_length)/(1024*1024),0)
from tables
union
select ' |
Buffer Size (MB):',
' | ',
format(sum(variable_value+0)/(1024*1024),0)
from global_variables
where lower(variable_name) like '%buffer_size' or lower(variable_name) like '%buffer_pool_size'
union
select ' |
Logging Bin. :', ' | ', variable_value
from 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 global_status g1,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 global_status g1,global_status g2
where g1.variable_name='INNODB_OS_LOG_WRITTEN'
and g2.variable_name='UPTIME'
union
select ' |
Hostname :', ' | ', variable_value
from information_schema.global_variables
where variable_name ='hostname'
union
select ' |
Port :', ' | ', variable_value
from information_schema.global_variables
where variable_name ='port';
select ' |
Version check |
' ;
select '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','5.5'), 'YES', 'NO') ; -- supported version BOTH MySQL MariaDB
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 ('10.4.11','10.3.21','10.2.30','10.1.43','5.5.66',
'10.4.12','10.3.22','10.2.31','10.1.44','5.5.67',
'10.4.13','10.3.23','10.2.32','10.1.45','5.5.68'), 'YES', 'NO') ; -- last2 MariaDB updates (and the next)
select ' | ', if(SUBSTRING_INDEX(version(),'-',1)
in ('10.4.12','10.3.22','10.2.31','10.1.44','5.5.67',
'10.4.13','10.3.23','10.2.32','10.1.45','5.5.68'), 'YES', 'NO') ; -- last updates (and the next)
select ' Last Releases (MariaDB): 10.4.12, 10.3.22, 10.2.31, 10.1.44, 5.5.67' from dual;
select ' | Last Releases (MySQL): 8.0.19, 5.7.29, 5.6.47' from dual; -- notes
select ' |
Schema/Object Matrix |
' ;
select '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 ' |
Tuning Parameters (most used ones) |
';
select 'Parameter',
' | Value | Type' ;
select ' |
', variable_name, ' | ', variable_value, ' | Flag'
from global_variables
where lower(variable_name) in (
'log_bin',
'query_cache_type',
'slow_query_log',
'foo')
union
select ' |
', variable_name, ' | ', format(variable_value,0), ' | Cache'
from 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 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 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 variable_name;
select ' |
Users with poor passwords |
' ;
select 'Host',
' | User',
' | Password',
' | Note';
SELECT ' |
',host,
' | ', user,
' | ',
' | Empty password'
FROM mysql.user
WHERE password='';
SELECT ' |
',host,
' | ', user,
' | ', password,
' | Same as username'
FROM mysql.user
WHERE password =UPPER(CONCAT('*', CAST(SHA1(UNHEX(SHA1(user))) AS CHAR)));
SELECT ' |
',host,
' | ', user,
' | ', password,
' | Same as username'
FROM mysql.user
WHERE password = BINARY old_password(user);
-- Known hash: root, secret, password, mypass, public, private, 1234, admin, secure, pass, mysql, my123, ...
SELECT ' |
',host,
' | ', user,
' | ', password,
' | Weak password'
FROM mysql.user
WHERE password in ('*81F5E21E35407D884A6CD4A731AEBFB6AF209E1B', '*14E65567ABDB5135D0CFD9A70B3032C179A49EE7',
'*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19', '*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF4',
'*A80082C9E4BB16D9C8E41B0D7EED46126DF4A46E', '*85BB02300F877EB061967510E83F68B1A7325252',
'*A4B6157319038724E3560894F7F932C8886EBFCF', '*4ACFE3202A5FF5CF467898FC58AAB1D615029441',
'*A36BA850A6E748679226B01E159EF1A7BF946195', '*196BDEDE2AE4F84CA44C47D54D78478C7E2BD7B7',
'*E74858DB86EBA20BC33D0AECAE8A8108C56B17FA', '*AF35041D44DF3E88C9F97CC8D3ACAF4695E65B69',
password('prova'), password('test'), password('demo'), password('qwerty'), password('manager'),
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,
' | ', password,
' | Weak password'
FROM mysql.user
WHERE password in (old_password('root'), old_password('secret'), old_password('password'), old_password('mypass'),
old_password('public'), old_password('private'), old_password('1234'), old_password('admin'),
old_password('secure'), old_password('pass'), old_password('mysql'), old_password('my123'),
old_password('prova'), old_password('test'), old_password('demo'), old_password('qwerty'),
old_password('manager'), old_password('moodle'), old_password('drupal'), old_password('admin01'),
old_password('joomla'), old_password('wp'), old_password('ilikerandompasswords'), old_password('changeme') );
SELECT ' |
',host,
' | ', user,
' | ', password,
' | Old [pre 4.1] password format'
FROM mysql.user
WHERE password not like '*%' and password<>'' and password<>'invalid';
SELECT ' |
',host,
' | ', user,
' | ', authentication_string,
' | Suspect backdoor user'
FROM mysql.user
WHERE user in ('hanako', 'kisadminnew1', '401hk$', 'guest', 'Huazhongdiguo110');
select ' |
Performance Statistics Summary |
' ;
select 'Statistic | Value | Suggested value | Action to correct';
select ' |
', variable_name, ' (days) | ', round(variable_value/(3600*24),1), '', ''
from 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 global_status t1, 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 global_status t1, 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 global_status t1, 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 global_status t1, global_status t2
where t1.variable_name='INNODB_LOG_WRITES' and t2.variable_name='INNODB_LOG_WRITE_REQUESTS'
union
select ' |
', 'Query Cache: Efficiency',
' | ', format(t1.variable_value*100/(t1.variable_value+t2.variable_value),2), ' | >30', ' | '
from global_status t1, global_status t2
where t1.variable_name='QCACHE_HITS'
and t2.variable_name='COM_SELECT'
union
select ' |
', 'Query Cache: Hit Ratio',
' | ', format(t1.variable_value*100/(t1.variable_value+t2.variable_value),2), ' | >80', ' | '
from global_status t1, 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 global_status s, 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 global_status
where variable_name='THREADS_RUNNING'
union
select ' |
', variable_name, ' | ', format(variable_value,0), ' | LOW', ' | Check application'
from global_status
where variable_name='SLOW_QUERIES'
union
select ' |
', g1.variable_name, ' #/sec. | ', format(g1.variable_value/g2.variable_value,5), '', ''
from global_status g1,global_status g2
where g1.variable_name='QUESTIONS'
and g2.variable_name='UPTIME'
union
select ' |
', g1.variable_name, ' #/sec. | ', format(g1.variable_value/g2.variable_value,5), '', ''
from global_status g1,global_status g2
where g1.variable_name='COM_SELECT'
and g2.variable_name='UPTIME'
union
select ' |
', g1.variable_name, ' #/sec. (TPS) | ', format(g1.variable_value/g2.variable_value,5), '', ''
from global_status g1,global_status g2
where g1.variable_name='COM_COMMIT'
and g2.variable_name='UPTIME'
union
select ' |
', g1.variable_name, ' #/sec. | ', format(g1.variable_value/g2.variable_value,5), '', ''
from global_status g1,global_status g2
where g1.variable_name='CONNECTIONS'
and g2.variable_name='UPTIME'
union
select ' |
','COM DML #/sec.',' | ',
format((g1.variable_value+g3.variable_value+g4.variable_value+g5.variable_value+g6.variable_value
+g7.variable_value+g8.variable_value+g9.variable_value)/g2.variable_value,5),
'', ''
from global_status g1,global_status g2,global_status g3,global_status g4,global_status g5,
global_status g6,global_status g7,global_status g8,global_status g9
where g1.variable_name='COM_INSERT'
and g2.variable_name='UPTIME'
and g3.variable_name='COM_UPDATE'
and g4.variable_name='COM_DELETE'
and g5.variable_name='COM_INSERT_SELECT'
and g6.variable_name='COM_UPDATE_MULTI'
and g7.variable_name='COM_DELETE_MULTI'
and g8.variable_name='COM_REPLACE'
and g9.variable_name='COM_REPLACE_SELECT'
union
select ' |
', g1.variable_name, ' Mb/sec. | ',
format(g1.variable_value*8/(g2.variable_value*1024*1024),5), '', ''
from global_status g1,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 global_status g1,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 information_schema.global_status, performance_schema.events_statements_summary_global_by_event_name
where variable_name='UPTIME'
order by 1;
select ' |
Expert suggestions on | Value | | Action to correct';
select ' |
', g1.variable_name, ' #/hour | ',
format((g1.variable_value*60*60)/g2.variable_value,5), ' | ', ' | Increase TABLE_OPEN_CACHE'
from global_status g1,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 global_status g1,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 global_status g1,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.2
union
select ' |
', g1.variable_name, ' % | ',
format(g1.variable_value*100/(g2.variable_value),5), ' | ', ' | Increase BINLOG_CACHE_SIZE'
from global_status g1,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 global_status g1,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 global_status g1,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 ' |