Skip to content

Instantly share code, notes, and snippets.

@cPFence
Last active March 19, 2025 02:06
Show Gist options
  • Save cPFence/98c359cfade030fd62adb6681312a97a to your computer and use it in GitHub Desktop.
Save cPFence/98c359cfade030fd62adb6681312a97a to your computer and use it in GitHub Desktop.
#!/bin/sh
# Script by cPFence Team, https://cpfence.app
mysql -e "show variables; show status" | awk '
{
VAR[$1]=$2
}
END {
MAX_CONN = VAR["max_connections"]
MAX_USED_CONN = VAR["Max_used_connections"]
BASE_MEM=VAR["key_buffer_size"] + VAR["query_cache_size"] + VAR["innodb_buffer_pool_size"] + VAR["innodb_additional_mem_pool_size"] + VAR["innodb_log_buffer_size"]
MEM_PER_CONN=VAR["read_buffer_size"] + VAR["read_rnd_buffer_size"] + VAR["sort_buffer_size"] + VAR["join_buffer_size"] + VAR["binlog_cache_size"] + VAR["thread_stack"] + VAR["tmp_table_size"] + VAR["max_heap_table_size"]
MEM_TOTAL_MIN=BASE_MEM + MEM_PER_CONN*MAX_USED_CONN
MEM_TOTAL_MAX=BASE_MEM + MEM_PER_CONN*MAX_CONN
printf "+------------------------------------------+--------------------+\n"
printf "| %40s | %15.3f MB |\n", "key_buffer_size", VAR["key_buffer_size"]/1048576
printf "| %40s | %15.3f MB |\n", "query_cache_size", VAR["query_cache_size"]/1048576
printf "| %40s | %15.3f MB |\n", "innodb_buffer_pool_size", VAR["innodb_buffer_pool_size"]/1048576
printf "| %40s | %15.3f MB |\n", "innodb_additional_mem_pool_size", VAR["innodb_additional_mem_pool_size"]/1048576
printf "| %40s | %15.3f MB |\n", "innodb_log_buffer_size", VAR["innodb_log_buffer_size"]/1048576
printf "| %40s | %15.3f MB |\n", "max_allowed_packet", VAR["max_allowed_packet"]/1048576
printf "+------------------------------------------+--------------------+\n"
printf "| %40s | %15.3f MB |\n", "BASE MEMORY", BASE_MEM/1048576
printf "+------------------------------------------+--------------------+\n"
printf "| %40s | %15.3f MB |\n", "sort_buffer_size", VAR["sort_buffer_size"]/1048576
printf "| %40s | %15.3f MB |\n", "read_buffer_size", VAR["read_buffer_size"]/1048576
printf "| %40s | %15.3f MB |\n", "read_rnd_buffer_size", VAR["read_rnd_buffer_size"]/1048576
printf "| %40s | %15.3f MB |\n", "join_buffer_size", VAR["join_buffer_size"]/1048576
printf "| %40s | %15.3f MB |\n", "thread_stack", VAR["thread_stack"]/1048576
printf "| %40s | %15.3f MB |\n", "binlog_cache_size", VAR["binlog_cache_size"]/1048576
printf "| %40s | %15.3f MB |\n", "tmp_table_size", VAR["tmp_table_size"]/1048576
printf "| %40s | %15.3f MB |\n", "max_heap_table_size", VAR["max_heap_table_size"]/1048576
printf "| %40s | %15.3f MB |\n", "query_cache_limit", VAR["query_cache_limit"]/1048576
printf "+------------------------------------------+--------------------+\n"
printf "| %40s | %15.3f MB |\n", "MEMORY PER CONNECTION", MEM_PER_CONN/1048576
printf "+------------------------------------------+--------------------+\n"
printf "| %40s | %18d |\n", "Max_used_connections", MAX_USED_CONN
printf "| %40s | %18d |\n", "max_connections", MAX_CONN
printf "| %40s | %18d |\n", "max_user_connections", VAR["max_user_connections"]
printf "| %40s | %18s |\n", "default-storage-engine", VAR["default-storage-engine"]
printf "| %40s | %18s |\n", "innodb_flush_method", VAR["innodb_flush_method"]
printf "| %40s | %18s |\n", "query_cache_type", VAR["query_cache_type"]
printf "+------------------------------------------+--------------------+\n"
printf "| %40s | %18d |\n", "open_files_limit", VAR["open_files_limit"]
printf "| %40s | %18d |\n", "table_open_cache", VAR["table_open_cache"]
printf "| %40s | %18d |\n", "innodb_open_files", VAR["innodb_open_files"]
printf "| %40s | %18d |\n", "innodb_file_per_table", VAR["innodb_file_per_table"]
printf "+------------------------------------------+--------------------+\n"
printf "| %40s | %15.3f MB |\n", "TOTAL (MIN)", MEM_TOTAL_MIN/1048576
printf "| %40s | %15.3f MB |\n", "TOTAL (MAX)", MEM_TOTAL_MAX/1048576
printf "+------------------------------------------+--------------------+\n"
printf "| %40s | %18s |\n", "wait_timeout", VAR["wait_timeout"]
printf "| %40s | %18s |\n", "interactive_timeout", VAR["interactive_timeout"]
printf "+------------------------------------------+--------------------+\n"
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment