昨天才第一次知道还有tuning-primer.sh这么个参数调优的脚本,然后和小周进行了分享,早上收到邮件他说这个脚本的数据不是很准确。于是就查看了它的代码,解析如下:
3:检查socket,如果第一次配置后保存到了~/my.cnf,那么就直接去~/my.cnf取,要么就用/var/lib/mysql/mysql.sock 或者/var/run/mysqld/mysqld.sock或者/tmp/mysql.sock。如果都没有,那就报个错出来
- check_used_connections () {
-
-
## -- Used Connections -- ##
## --获取参数值和状态值
-
mysql_variable \'max_connections\' max_connections
-
mysql_status \'Max_used_connections\' max_used_connections
-
mysql_status \'Threads_connected\' threads_connected
## --计算使用率了
-
connections_ratio=$(($max_used_connections*100/$max_connections))
## --打印当前参数设置的值和状态值
-
cecho "MAX CONNECTIONS" boldblue
-
cecho "Current max_connections = $max_connections"
-
cecho "Current threads_connected = $threads_connected"
-
cecho "Historic max_used_connections = $max_used_connections"
-
cechon "The number of used connections is "
## 在这里进行分析了,算法就就在这里,我们也可以自己改,什么值显示什么颜色啥的。
-
if [ $connections_ratio -ge 85 ] ; then
-
txt_color=red
-
error=1
-
elif [ $connections_ratio -le 10 ] ; then
-
txt_color=red
-
error=2
-
else
-
txt_color=green
-
error=0
-
fi
## --打印分析结果了
-
# cechon "$max_used_connections " $txt_color
-
# cechon "which is "
-
cechon "$connections_ratio% " $txt_color
-
cecho "of the configured maximum."
## 打印建议信息
-
if [ $error -eq 1 ] ; then
-
cecho "You should raise max_connections" $txt_color
-
elif [ $error -eq 2 ] ; then
-
cecho "You are using less than 10% of your configured max_connections." $txt_color
-
cecho "Lowering max_connections could help to avoid an over-allocation of memory" $txt_color
-
cecho "See \"MEMORY USAGE\" section to make sure you are not over-allocating" $txt_color
-
else
-
cecho "Your max_connections variable seems to be fine." $txt_color
-
fi
-
unset txt_color
-
}