我怎样才能快速地看到一个可读的MySQL正常运行时间?

我想以一种有用的方式快速获得mysql的正常运行时间,而不仅仅是从GLOBAL STATUS转储秒,然后做一些math计算。 有没有办法在Linux上完成这个?

这个小脚本以“1天4小时35分钟”的格式转储正常运行时间。 它只列出几秒钟,这是当前超过0的值和正常运行时间超过1天的时间。

#/bin/sh # Prints the uptime of mysql # Optional: Takes one argument for the servername, default is localhost # Set $host if [ $1 ]; then host=$1 else host="localhost" fi #Get Uptime in seconds from mysql server s=`mysql -h $host --skip-column-names -e "select VARIABLE_VALUE from information_schema.GLOBAL_STATUS where VARIABLE_NAME='Uptime';"` #Takes seconds, outputs human readable time #Function Source: http://unix.stackexchange.com/a/170299/17808 converts() { local t=$1 local d=$((t/60/60/24)) local h=$((t/60/60%24)) local m=$((t/60%60)) local s=$((t%60)) if [[ $d > 0 ]]; then [[ $d = 1 ]] && echo -n "$d day " || echo -n "$d days " fi if [[ $h > 0 ]]; then [[ $h = 1 ]] && echo -n "$h hour " || echo -n "$h hours " fi if [[ $m > 0 ]]; then [[ $m = 1 ]] && echo -n "$m minute " || echo -n "$m minutes " fi if [[ $d = 0 && $h = 0 && $m = 0 ]]; then [[ $s = 1 ]] && echo -n "$s second" || echo -n "$s seconds" fi echo } #Convert seconds to readable time converts $s