mysql-stat.sh error
SirMaxBlack opened this issue · comments
Добрый день.
При попытке запустить mysql-stat.sh, выдает ошибку:
Simple MySQL database server statistics v1.5
Written by Mikhail Grigorev (sleuthhound@gmail.com, https://blog.programs74.ru)
awk: cmd. line:17: (FILENAME=- FNR=1218) fatal: division by zero attempted
Как можно пофиксить?
Добрый день, на какой ОС запускаете? Какая версия MySQL?
Система: "Debian GNU/Linux 11 (bullseye)"
Мария: Your MariaDB connection id is 131040
Server version: 10.5.15-MariaDB-0+deb11u1 Debian 11
Непонятная ошибка (на debian 10 все нормально работает, 11 нет под руками чтобы проверить), запустите пожалуйста скрипт так
bash -x ./mysql-stat.sh
и пришлите весь вывод
+ VERSION=1.5
+ SOURCE=./mysql-stat.sh
+ '[' -h ./mysql-stat.sh ']'
+++ dirname ./mysql-stat.sh
++ cd -P .
++ pwd
+ SCRIPT_DIR=/root
++ basename ./mysql-stat.sh
+ SCRIPT_NAME=mysql-stat.sh
+ echo ''
+ echo 'Simple MySQL database server statistics v1.5'
Simple MySQL database server statistics v1.5
+ echo 'Written by Mikhail Grigorev (sleuthhound@gmail.com, https://blog.programs74.ru)'
Written by Mikhail Grigorev (sleuthhound@gmail.com, https://blog.programs74.ru)
+ echo ''
+ trap ctrl_c INT
+ _command_exists mysql
+ type mysql
++ which mysql
+ MYSQL_BIN=/usr/bin/mysql
+ [[ '' == -* ]]
+ [[ ! -n '' ]]
+ LOG_FILE=/root/mysql_stat.log
+ [[ ! -f /root/mysql_stat.log ]]
+ touch /root/mysql_stat.log
+ [[ ! -n '' ]]
+ [[ -f /root/.my.cnf ]]
+ '[' -z '' ']'
+ MYSQL_USER=root
+ MYSQL='/usr/bin/mysql -uroot'
+ '[' -n '' ']'
+ '[' -n '' ']'
+ '[' -n '' ']'
+ echo 'Error: MySQL password for user '\''root'\'' is empty, please change password and create settings file '\''/root/.my.cnf'\''.'
Error: MySQL password for user 'root' is empty, please change password and create settings file '/root/.my.cnf'.
+ echo
+ _show_help
+ echo -e '\t--help -h\t\tthis menu'
--help -h this menu
+ echo -e '\t--user username\t\tspecify mysql username to use, the script will prompt for a password during runtime, unless you supply a password'
--user username specify mysql username to use, the script will prompt for a password during runtime, unless you supply a password
+ echo -e '\t--password "yourpass"'
--password "yourpass"
+ echo -e '\t--host hostname\t\tspecify mysql hostname to use, be it local (default) or remote'
--host hostname specify mysql hostname to use, be it local (default) or remote
+ echo -e '\t--port port\t\tspecify mysql port number to use, be it 3306 (default)'
--port port specify mysql port number to use, be it 3306 (default)
+ exit 1
Могу попробовать с учетными данными
+ VERSION=1.5
+ SOURCE=./mysql-stat.sh
+ '[' -h ./mysql-stat.sh ']'
+++ dirname ./mysql-stat.sh
++ cd -P .
++ pwd
+ SCRIPT_DIR=/root
++ basename ./mysql-stat.sh
+ SCRIPT_NAME=mysql-stat.sh
+ echo ''
+ echo 'Simple MySQL database server statistics v1.5'
Simple MySQL database server statistics v1.5
+ echo 'Written by Mikhail Grigorev (sleuthhound@gmail.com, https://blog.programs74.ru)'
Written by Mikhail Grigorev (sleuthhound@gmail.com, https://blog.programs74.ru)
+ echo ''
+ trap ctrl_c INT
+ _command_exists mysql
+ type mysql
++ which mysql
+ MYSQL_BIN=/usr/bin/mysql
+ [[ --user == -* ]]
+ case "$1" in
+ MYSQL_USER=root
+ shift 2
+ [[ --password == -* ]]
+ case "$1" in
+ MYSQL_PASSWD=MyPassword
+ shift 2
+ [[ '' == -* ]]
+ [[ ! -n '' ]]
+ LOG_FILE=/root/mysql_stat.log
+ [[ ! -f /root/mysql_stat.log ]]
+ [[ ! -n root ]]
+ '[' -z root ']'
+ MYSQL='/usr/bin/mysql -uroot'
+ '[' -n '' ']'
+ '[' -n '' ']'
+ '[' -n MyPassword ']'
+ export MYSQL_PWD=MyPassword
+ MYSQL_PWD=MyPassword
+ '[' -f /root/.my.cnf ']'
+ /usr/bin/mysql -uroot --skip-column-names --batch -e 'SELECT 1;'
+ '[' 0 -ne 0 ']'
+ /usr/bin/mysql -uroot -e 'show variables; show status'
+ awk '
{
VAR[$1]=$2
}
END {
split(VAR["version"],VERSION,"-")
UPTIME = VAR["Uptime"]
MAX_CONN = VAR["max_connections"]
MAX_USED_CONN = VAR["Max_used_connections"]
BASE_MEM=VAR["key_buffer_size"] + VAR["query_cache_size"] + VAR["tmp_table_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"]
MEM_TOTAL_MIN=BASE_MEM + MEM_PER_CONN*MAX_USED_CONN
MEM_TOTAL_MAX=BASE_MEM + MEM_PER_CONN*MAX_CONN
if (VAR["query_cache_size"]) {
QUERY_CACHE_FREE=VAR["Qcache_free_memory"]*100/VAR["query_cache_size"]
QUERY_CACHE_USAGE=((VAR["query_cache_size"]-VAR["Qcache_free_memory"])/VAR["query_cache_size"])*100
QUERY_CACHE_HIT_RATE=((VAR["Qcache_hits"]/(VAR["Qcache_hits"]+VAR["Qcache_inserts"]+VAR["Qcache_not_cached"]))*100)
}
printf "+------------------------------------------+--------------------+\n"
printf "| %40s | %18s |\n", "Version", VERSION[1]
printf "| %40s | %9dh:%dm:%ds |\n", "Uptime", UPTIME/3600, UPTIME%3600/60, UPTIME%60
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", "tmp_table_size", VAR["tmp_table_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 "+------------------------------------------+--------------------+\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 "+------------------------------------------+--------------------+\n"
printf "| %40s | %15.3f MB |\n", "MEMORY PER CONNECTION", MEM_PER_CONN/1048576
printf "+------------------------------------------+--------------------+\n"
printf "| %40s | %15.3f MB |\n", "myisam_sort_buffer_size", VAR["myisam_sort_buffer_size"]/1048576
printf "+------------------------------------------+--------------------+\n"
printf "| %40s | %18d |\n", "Max_used_connections", MAX_USED_CONN
printf "| %40s | %18d |\n", "max_connections", MAX_CONN
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 | %17.1f% |\n", " QUERY_CACHE_USAGE (%)", QUERY_CACHE_USAGE
printf "| %40s | %17.1f% |\n", " QUERY_CACHE_FREE (%)", QUERY_CACHE_FREE
printf "| %40s | %17.1f% |\n", " QUERY_CACHE_HIT_RATE (%)", QUERY_CACHE_HIT_RATE
printf "+------------------------------------------+--------------------+\n"
}'
awk: cmd. line:17: (FILENAME=- FNR=1218) fatal: division by zero attempted
+ [[ ! -s /root/mysql_stat.log ]]
+ rm -f /root/mysql_stat.log
@SirMaxBlack Пришлите пожалуйста на мой email файл с результатом команды
mysql -U root -p --skip-column-names --batch -e "show variables; show status;" > stat.txt
Отправил
Спасибо! Проблема исправлена, скачайте свежую версию скрипта