ITPub博客

首页 > 数据库 > MySQL > Tuning-primer.sh 2011版本

Tuning-primer.sh 2011版本

原创 MySQL 作者:Michael_DD 时间:2015-02-09 14:05:12 0 删除 编辑
Tuning-primer.sh  2011版本

2011版本

点击(此处)折叠或打开

  1. #!/bin/sh

  2. # vim: ts=8
  3. #########################################################################
  4. #                                    #
  5. #    MySQL performance tuning primer script                #
  6. #    Writen by: Matthew Montgomery                    #
  7. #    Report bugs to: https://bugs.launchpad.net/mysql-tuning-primer    #
  8. #    Inspired by: MySQLARd (http://gert.sos.be/demo/mysqlar/)    #
  9. #    Version: 1.6-r1        Released: 2011-08-06            #
  10. #    Licenced under GPLv2 #
  11. #                                    #
  12. #########################################################################

  13. #########################################################################
  14. #                                    #
  15. #    Usage: ./tuning-primer.sh [ mode ]                 #
  16. #                                    #
  17. #    Available Modes:                         #
  18. #        all :         perform all checks (default)        #
  19. #        prompt :     prompt for login credintials and socket    #
  20. #                and execution mode            #
  21. #         mem, memory :     run checks for tunable options which    #
  22. #                effect memory usage            #
  23. #        disk, file :    run checks for options which effect    #
  24. #                i/o performance or file handle limits    #
  25. #        innodb :    run InnoDB checks /* to be improved */    #
  26. #        misc :         run checks for that don\'t categorise    #
  27. #                well Slow Queries, Binary logs,        #
  28. #                Used Connections and Worker Threads    #
  29. #########################################################################
  30. #                                    #
  31. # Set this socket variable ONLY if you have multiple instances running    #
  32. # or we are unable to find your socket, and you don\'t want to to be    #
  33. # prompted for input each time you run this script.            #
  34. #                                    #
  35. #########################################################################
  36. socket=

  37. export black=\'\\033[0m\'
  38. export boldblack=\'\\033[1;0m\'
  39. export red=\'\\033[31m\'
  40. export boldred=\'\\033[1;31m\'
  41. export green=\'\\033[32m\'
  42. export boldgreen=\'\\033[1;32m\'
  43. export yellow=\'\\033[33m\'
  44. export boldyellow=\'\\033[1;33m\'
  45. export blue=\'\\033[34m\'
  46. export boldblue=\'\\033[1;34m\'
  47. export magenta=\'\\033[35m\'
  48. export boldmagenta=\'\\033[1;35m\'
  49. export cyan=\'\\033[36m\'
  50. export boldcyan=\'\\033[1;36m\'
  51. export white=\'\\033[37m\'
  52. export boldwhite=\'\\033[1;37m\'


  53. cecho ()

  54. ## -- Function to easliy print colored text -- ##
  55.     
  56.     # Color-echo.
  57.     # Argument $1 = message
  58.     # Argument $2 = color
  59. {
  60. local default_msg=\"No message passed.\"

  61. message=${1:-$default_msg}    # Defaults to default message.

  62. #change it for fun
  63. #We use pure names
  64. color=${2:-black}        # Defaults to black, if not specified.

  65. case $color in
  66.     black)
  67.          printf \"$black\" ;;
  68.     boldblack)
  69.          printf \"$boldblack\" ;;
  70.     red)
  71.          printf \"$red\" ;;
  72.     boldred)
  73.          printf \"$boldred\" ;;
  74.     green)
  75.          printf \"$green\" ;;
  76.     boldgreen)
  77.          printf \"$boldgreen\" ;;
  78.     yellow)
  79.          printf \"$yellow\" ;;
  80.     boldyellow)
  81.          printf \"$boldyellow\" ;;
  82.     blue)
  83.          printf \"$blue\" ;;
  84.     boldblue)
  85.          printf \"$boldblue\" ;;
  86.     magenta)
  87.          printf \"$magenta\" ;;
  88.     boldmagenta)
  89.          printf \"$boldmagenta\" ;;
  90.     cyan)
  91.          printf \"$cyan\" ;;
  92.     boldcyan)
  93.          printf \"$boldcyan\" ;;
  94.     white)
  95.          printf \"$white\" ;;
  96.     boldwhite)
  97.          printf \"$boldwhite\" ;;
  98. esac
  99.   printf \"%s\\n\" \"$message\"
  100.   tput sgr0            # Reset to normal.
  101.   printf \"$black\"

  102. return
  103. }


  104. cechon ()        

  105. ## -- Function to easliy print colored text -- ##

  106.     # Color-echo.
  107.     # Argument $1 = message
  108.     # Argument $2 = color
  109. {
  110. local default_msg=\"No message passed.\"
  111.                 # Doesn\'t really need to be a local variable.

  112. message=${1:-$default_msg}    # Defaults to default message.

  113. #change it for fun
  114. #We use pure names
  115. color=${2:-black}        # Defaults to black, if not specified.

  116. case $color in
  117.     black)
  118.         printf \"$black\" ;;
  119.     boldblack)
  120.         printf \"$boldblack\" ;;
  121.     red)
  122.         printf \"$red\" ;;
  123.     boldred)
  124.         printf \"$boldred\" ;;
  125.     green)
  126.         printf \"$green\" ;;
  127.     boldgreen)
  128.         printf \"$boldgreen\" ;;
  129.     yellow)
  130.         printf \"$yellow\" ;;
  131.     boldyellow)
  132.         printf \"$boldyellow\" ;;
  133.     blue)
  134.         printf \"$blue\" ;;
  135.     boldblue)
  136.         printf \"$boldblue\" ;;
  137.     magenta)
  138.         printf \"$magenta\" ;;
  139.     boldmagenta)
  140.         printf \"$boldmagenta\" ;;
  141.     cyan)
  142.         printf \"$cyan\" ;;
  143.     boldcyan)
  144.         printf \"$boldcyan\" ;;
  145.     white)
  146.         printf \"$white\" ;;
  147.     boldwhite)
  148.         printf \"$boldwhite\" ;;
  149. esac
  150.   printf \"%s\" \"$message\"
  151.   tput sgr0            # Reset to normal.
  152.   printf \"$black\"

  153. return
  154. }


  155. print_banner () {

  156. ## -- Banner -- ##

  157. cecho \"    -- MYSQL PERFORMANCE TUNING PRIMER --\" boldblue
  158. cecho \"     - By: Matthew Montgomery -\" black

  159. }

  160. ## -- Find the location of the mysql.sock file -- ##

  161. check_for_socket () {
  162.     if [ -z \"$socket\" ] ; then
  163.         # Use ~/my.cnf version
  164.         if [ -f ~/.my.cnf ] ; then
  165.             cnf_socket=$(grep ^socket ~/.my.cnf | awk -F \\= \'{ print $2 }\' | head -1)
  166.         fi
  167.         if [ -S \"$cnf_socket\" ] ; then
  168.             socket=$cnf_socket
  169.         elif [ -S /var/lib/mysql/mysql.sock ] ; then
  170.             socket=/var/lib/mysql/mysql.sock
  171.         elif [ -S /var/run/mysqld/mysqld.sock ] ; then
  172.             socket=/var/run/mysqld/mysqld.sock
  173.         elif [ -S /tmp/mysql.sock ] ; then
  174.             socket=/tmp/mysql.sock
  175.         else
  176.             if [ -S \"$ps_socket\" ] ; then
  177.             socket=$ps_socket
  178.             fi
  179.         fi
  180.     fi
  181.     if [ -S \"$socket\" ] ; then
  182.         echo UP > /dev/null
  183.     else
  184.         cecho \"No valid socket file \\\"$socket\\\" found!\" boldred
  185.         cecho \"The mysqld process is not running or it is installed in a custom location.\" red
  186.         cecho \"If you are sure mysqld is running, execute script in \\\"prompt\\\" mode or set \" red
  187.         cecho \"the socket= variable at the top of this script\" red
  188.         exit 1
  189.     fi
  190. }


  191. check_for_plesk_passwords () {

  192. ## -- Check for the existance of plesk and login using it\'s credentials -- ##

  193.     if [ -f /etc/psa/.psa.shadow ] ; then
  194.      mysql=\"mysql -S $socket -u admin -p$(cat /etc/psa/.psa.shadow)\"
  195.      mysqladmin=\"mysqladmin -S $socket -u admin -p$(cat /etc/psa/.psa.shadow)\"
  196.     else
  197.      mysql=\"mysql\"
  198.      mysqladmin=\"mysqladmin\"
  199.      # mysql=\"mysql -S $socket\"
  200.      # mysqladmin=\"mysqladmin -S $socket\"
  201.     fi
  202. }

  203. check_mysql_login () {

  204. ## -- Test for running mysql -- ##

  205.     is_up=$($mysqladmin ping 2>&1)
  206.     if [ \"$is_up\" = \"mysqld is alive\" ] ; then
  207.         echo UP > /dev/null
  208.          # echo $is_up
  209.     elif [ \"$is_up\" != \"mysqld is alive\" ] ; then
  210.         printf \"\\n\"
  211.         cecho \"Using login values from ~/.my.cnf\"
  212.         cecho \"- INITIAL LOGIN ATTEMPT FAILED -\" boldred
  213.         if [ -z $prompted ] ; then
  214.         find_webmin_passwords
  215.         else
  216.             return 1
  217.         fi
  218.         
  219.     else
  220.         cecho \"Unknow exit status\" red
  221.         exit -1
  222.     fi
  223. }

  224. final_login_attempt () {
  225.         is_up=$($mysqladmin ping 2>&1)
  226.         if [ \"$is_up\" = \"mysqld is alive\" ] ; then
  227.                 echo UP > /dev/null
  228.         elif [ \"$is_up\" != \"mysqld is alive\" ] ; then
  229.                 cecho \"- FINAL LOGIN ATTEMPT FAILED -\" boldred
  230.         cecho \"Unable to log into socket: $socket\" boldred
  231.                 exit 1
  232.         fi
  233. }

  234. second_login_failed () {

  235. ## -- create a ~/.my.cnf and exit when all else fails -- ##

  236.     cecho \"Could not auto detect login info!\"
  237.     cecho \"Found potential sockets: $found_socks\"
  238.     cecho \"Using: $socket\" red
  239.     read -p \"Would you like to provide a different socket?: [y/N] \" REPLY
  240.         case $REPLY in
  241.             yes | y | Y | YES)
  242.             read -p \"Socket: \" socket
  243.             ;;
  244.         esac
  245.     read -p \"Do you have your login handy ? [y/N] : \" REPLY
  246.     case $REPLY in
  247.         yes | y | Y | YES)
  248.         answer1=\'yes\'
  249.         read -p \"User: \" user
  250.         read -rp \"Password: \" pass
  251.         if [ -z $pass ] ; then
  252.         export mysql=\"$mysql -S$socket -u$user\"
  253.         export mysqladmin=\"$mysqladmin -S$socket -u$user\"
  254.         else
  255.         export mysql=\"$mysql -S$socket -u$user -p$pass\"
  256.         export mysqladmin=\"$mysqladmin -S$socket -u$user -p$pass\"
  257.         fi
  258.         ;;
  259.         *)
  260.         cecho \"Please create a valid login to MySQL\"
  261.         cecho \"Or, set correct values for \'user=\' and \'password=\' in ~/.my.cnf\"
  262.         ;;
  263.     esac
  264.     cecho \" \"
  265.     read -p \"Would you like me to create a ~/.my.cnf file for you? [y/N] : \" REPLY
  266.         case $REPLY in
  267.      yes | y | Y | YES)
  268.         answer2=\'yes\'
  269.         if [ ! -f ~/.my.cnf ] ; then
  270.             umask 077
  271.             printf \"[client]\\nuser=$user\\npassword=$pass\\nsocket=$socket\" > ~/.my.cnf
  272.             if [ \"$answer1\" != \'yes\' ] ; then
  273.                 exit 1
  274.             else
  275.                 final_login_attempt
  276.                 return 0
  277.             fi
  278.         else
  279.             printf \"\\n\"
  280.             cecho \"~/.my.cnf already exists!\" boldred
  281.             printf \"\\n\"
  282.             read -p \"Replace ? [y/N] : \" REPLY
  283.             if [ \"$REPLY\" = \'y\' ] || [ \"$REPLY\" = \'Y\' ] ; then
  284.             printf \"[client]\\nuser=$user\\npassword=$pass\\socket=$socket\" > ~/.my.cnf
  285.                 if [ \"$answer1\" != \'yes\' ] ; then
  286.                     exit 1
  287.                 else
  288.                     final_login_attempt
  289.                     return 0
  290.                 fi
  291.             else
  292.                 cecho \"Please set the \'user=\' and \'password=\' and \'socket=\' values in ~/.my.cnf\"
  293.                 exit 1
  294.             fi
  295.         fi
  296.         ;;
  297.         *)
  298.         if [ \"$answer1\" != \'yes\' ] ; then
  299.             exit 1
  300.         else
  301.             final_login_attempt
  302.             return 0
  303.         fi
  304.         ;;
  305.     esac
  306. }

  307. find_webmin_passwords () {

  308. ## -- populate the .my.cnf file using values harvested from Webmin -- ##

  309.     cecho \"Testing for stored webmin passwords:\"
  310.     if [ -f /etc/webmin/mysql/config ] ; then
  311.         user=$(grep ^login= /etc/webmin/mysql/config | cut -d \"=\" -f 2)
  312.         pass=$(grep ^pass= /etc/webmin/mysql/config | cut -d \"=\" -f 2)
  313.         if [ $user ] && [ $pass ] && [ ! -f ~/.my.cnf ] ; then
  314.             cecho \"Setting login info as User: $user Password: $pass\"
  315.             touch ~/.my.cnf
  316.             chmod 600 ~/.my.cnf
  317.             printf \"[client]\\nuser=$user\\npassword=$pass\" > ~/.my.cnf
  318.             cecho \"Retrying login\"
  319.             is_up=$($mysqladmin ping 2>&1)
  320.             if [ \"$is_up\" = \"mysqld is alive\" ] ; then
  321.                 echo UP > /dev/null
  322.             else
  323.                 second_login_failed
  324.             fi
  325.         echo
  326.         else
  327.             second_login_failed
  328.         echo
  329.         fi
  330.     else
  331.     cecho \" None Found\" boldred
  332.         second_login_failed
  333.     fi
  334. }

  335. #########################################################################
  336. #                                    #
  337. # Function to pull MySQL status variable                #
  338. #                                    #
  339. # Call using :                                #
  340. #    mysql_status \\\'Mysql_status_variable\\\' bash_dest_variable    #
  341. #                                    #
  342. #########################################################################

  343. mysql_status () {
  344.     local status=$($mysql -Bse \"show /*!50000 global */ status like $1\" | awk \'{ print $2 }\')
  345.     export \"$2\"=$status
  346. }

  347. #########################################################################
  348. #                                    #
  349. # Function to pull MySQL server runtime variable            #
  350. #                                    #
  351. # Call using :                                #
  352. #    mysql_variable \\\'Mysql_server_variable\\\' bash_dest_variable    #
  353. #    - OR -                                #
  354. #    mysql_variableTSV \\\'Mysql_server_variable\\\' bash_dest_variable    #
  355. #                                    #
  356. #########################################################################

  357. mysql_variable () {
  358.     local variable=$($mysql -Bse \"show /*!50000 global */ variables like $1\" | awk \'{ print $2 }\')
  359.     export \"$2\"=$variable
  360. }
  361. mysql_variableTSV () {
  362.         local variable=$($mysql -Bse \"show /*!50000 global */ variables like $1\" | awk -F \\t \'{ print $2 }\')
  363.         export \"$2\"=$variable
  364. }

  365. float2int () {
  366.         local variable=$(echo \"$1 / 1\" | bc -l)
  367.         export \"$2\"=$variable
  368. }

  369. divide () {

  370. # -- Divide two intigers -- #

  371.     usage=\"$0 dividend divisor \'$variable\' scale\"
  372.     if [ $1 -ge 1 ]    ; then
  373.         dividend=$1
  374.     else
  375.         cecho \"Invalid Dividend\" red
  376.         echo $usage
  377.         exit 1
  378.     fi
  379.     if [ $2 -ge 1 ] ; then
  380.         divisor=$2
  381.     else
  382.         cecho \"Invalid Divisor\" red
  383.         echo $usage
  384.         exit 1
  385.     fi
  386.     if [ ! -n $3 ] ; then
  387.         cecho \"Invalid variable name\" red
  388.         echo $usage
  389.         exit 1
  390.     fi
  391.     if [ -z $4 ] ; then
  392.         scale=2
  393.     elif [ $4 -ge 0 ] ; then
  394.         scale=$4
  395.     else
  396.         cecho \"Invalid scale\" red
  397.         echo $usage
  398.         exit 1
  399.     fi
  400.     export $3=$(echo \"scale=$scale; $dividend / $divisor\" | bc -l)
  401. }

  402. human_readable () {

  403. #########################################################################
  404. #                                    #
  405. # Convert a value in to human readable size and populate a variable    #
  406. # with the result.                            #
  407. #                                    #
  408. # Call using:                                #
  409. #    human_readable $value \'variable name\' [ places of precision]    #
  410. #                                    #
  411. #########################################################################

  412.     ## value=$1
  413.     ## variable=$2
  414.     scale=$3

  415.     if [ $1 -ge 1073741824 ] ; then
  416.         if [ -z $3 ] ; then
  417.             scale=2
  418.         fi
  419.         divide $1 1073741824 \"$2\" $scale
  420.         unit=\"G\"
  421.     elif [ $1 -ge 1048576 ] ; then
  422.         if [ -z $3 ] ; then
  423.             scale=0
  424.         fi
  425.         divide $1 1048576 \"$2\" $scale
  426.      unit=\"M\"
  427.     elif [ $1 -ge 1024 ] ; then
  428.         if [ -z $3 ] ; then
  429.             scale=0
  430.         fi
  431.         divide $1 1024 \"$2\" $scale
  432.      unit=\"K\"
  433.     else
  434.         export \"$2\"=$1
  435.      unit=\"bytes\"
  436.     fi
  437.     # let \"$2\"=$HR
  438. }

  439. human_readable_time () {

  440. ########################################################################
  441. #                                 #
  442. #    Function to produce human readable time #
  443. #                                 #
  444. ########################################################################

  445.     usage=\"$0 seconds \'variable\'\"
  446.     if [ -z $1 ] || [ -z $2 ] ; then
  447.         cecho $usage red
  448.         exit 1
  449.     fi
  450.     days=$(echo \"scale=0 ; $1 / 86400\" | bc -l)
  451.     remainder=$(echo \"scale=0 ; $1 % 86400\" | bc -l)
  452.     hours=$(echo \"scale=0 ; $remainder / 3600\" | bc -l)
  453.     remainder=$(echo \"scale=0 ; $remainder % 3600\" | bc -l)
  454.     minutes=$(echo \"scale=0 ; $remainder / 60\" | bc -l)
  455.     seconds=$(echo \"scale=0 ; $remainder % 60\" | bc -l)
  456.     export $2=\"$days days $hours hrs $minutes min $seconds sec\"
  457. }

  458. check_mysql_version () {

  459. ## -- Print Version Info -- ##

  460.     mysql_variable \\\'version\\\' mysql_version
  461.     mysql_variable \\\'version_compile_machine\\\' mysql_version_compile_machine
  462.     
  463. if [ \"$mysql_version_num\" -lt 050000 ]; then
  464.     cecho \"MySQL Version $mysql_version $mysql_version_compile_machine is EOL please upgrade to MySQL 4.1 or later\" boldred
  465. else
  466.     cecho \"MySQL Version $mysql_version $mysql_version_compile_machine\"
  467. fi


  468. }

  469. post_uptime_warning () {

  470. #########################################################################
  471. #                                    #
  472. # Present a reminder that mysql must run for a couple of days to    #
  473. # build up good numbers in server status variables before these tuning    #
  474. # suggestions should be used.                        #
  475. #                                    #
  476. #########################################################################

  477.     mysql_status \\\'Uptime\\\' uptime
  478.     mysql_status \\\'Threads_connected\\\' threads
  479.     queries_per_sec=$(($questions/$uptime))
  480.     human_readable_time $uptime uptimeHR

  481.     cecho \"Uptime = $uptimeHR\"
  482.     cecho \"Avg. qps = $queries_per_sec\"
  483.     cecho \"Total Questions = $questions\"
  484.     cecho \"Threads Connected = $threads\"
  485.     echo

  486.     if [ $uptime -gt 172800 ] ; then
  487.         cecho \"Server has been running for over 48hrs.\"
  488.         cecho \"It should be safe to follow these recommendations\"
  489.     else
  490.         cechon \"Warning: \" boldred
  491.         cecho \"Server has not been running for at least 48hrs.\" boldred
  492.         cecho \"It may not be safe to use these recommendations\" boldred

  493.     fi
  494.     echo \"\"
  495.     cecho \"To find out more information on how each of these\" red
  496.     cecho \"runtime variables effects performance visit:\" red
  497.     if [ \"$major_version\" = \'3.23\' ] || [ \"$major_version\" = \'4.0\' ] || [ \"$major_version\" = \'4.1\' ] ; then
  498.     cecho \"http://dev.mysql.com/doc/refman/4.1/en/server-system-variables.html\" boldblue
  499.     elif [ \"$major_version\" = \'5.0\' ] || [ \"$mysql_version_num\" -gt \'050100\' ]; then
  500.     cecho \"http://dev.mysql.com/doc/refman/$major_version/en/server-system-variables.html\" boldblue    
  501.     else
  502.     cecho \"UNSUPPORTED MYSQL VERSION\" boldred
  503.     exit 1
  504.     fi
  505.     cecho \"Visit http://www.mysql.com/products/enterprise/advisors.html\" boldblue
  506.     cecho \"for info about MySQL\'s Enterprise Monitoring and Advisory Service\" boldblue
  507. }

  508. check_slow_queries () {

  509. ## -- Slow Queries -- ##

  510.     cecho \"SLOW QUERIES\" boldblue

  511.     mysql_status \\\'Slow_queries\\\' slow_queries
  512.     mysql_variable \\\'long_query_time\\\' long_query_time
  513.     mysql_variable \\\'log%queries\\\' log_slow_queries
  514.     
  515.     prefered_query_time=5
  516.     if [ -e /etc/my.cnf ] ; then
  517.         if [ -z $log_slow_queries ] ; then
  518.             log_slow_queries=$(grep log-slow-queries /etc/my.cnf)
  519.         fi
  520.     fi

  521.     if [ \"$log_slow_queries\" = \'ON\' ] ; then
  522.         cecho \"The slow query log is enabled.\"
  523.     elif [ \"$log_slow_queries\" = \'OFF\' ] ; then
  524.         cechon \"The slow query log is \"
  525.         cechon \"NOT\" boldred
  526.         cecho \" enabled.\"
  527.     elif [ -z $log_slow_queries ] ; then
  528.         cechon \"The slow query log is \"
  529.         cechon \"NOT\" boldred
  530.         cecho \" enabled.\"
  531.     else
  532.         cecho \"Error: $log_slow_queries\" boldred
  533.     fi
  534.     cecho \"Current long_query_time = $long_query_time sec.\"
  535.     cechon \"You have \"
  536.     cechon \"$slow_queries\" boldred
  537.     cechon \" out of \"
  538.     cechon \"$questions\" boldred
  539.     cecho \" that take longer than $long_query_time sec. to complete\"
  540.     
  541.     float2int long_query_time long_query_timeInt

  542.     if [ $long_query_timeInt -gt $prefered_query_time ] ; then
  543.                 cecho \"Your long_query_time may be too high, I typically set this under $prefered_query_time sec.\" red
  544.     else
  545.         cecho \"Your long_query_time seems to be fine\" green
  546.     fi

  547. }

  548. check_binary_log () {

  549. ## -- Binary Log -- ##

  550.     cecho \"BINARY UPDATE LOG\" boldblue

  551.     mysql_variable \\\'log_bin\\\' log_bin
  552.     mysql_variable \\\'max_binlog_size\\\' max_binlog_size
  553.     mysql_variable \\\'expire_logs_days\\\' expire_logs_days
  554.     mysql_variable \\\'sync_binlog\\\' sync_binlog
  555.     # mysql_variable \\\'max_binlog_cache_size\\\' max_binlog_cache_size

  556.     if [ \"$log_bin\" = \'ON\' ] ; then
  557.         cecho \"The binary update log is enabled\"
  558.         if [ -z \"$max_binlog_size\" ] ; then
  559.             cecho \"The max_binlog_size is not set. The binary log will rotate when it reaches 1GB.\" red
  560.         fi
  561.         if [ \"$expire_logs_days\" -eq 0 ] ; then
  562.             cecho \"The expire_logs_days is not set.\" boldred
  563.             cechon \"The mysqld will retain the entire binary log until \" red
  564.             cecho \"RESET MASTER or PURGE MASTER LOGS commands are run manually\" red
  565.             cecho \"Setting expire_logs_days will allow you to remove old binary logs automatically\" yellow
  566.             cecho \"See http://dev.mysql.com/doc/refman/$major_version/en/purge-master-logs.html\" yellow
  567.         fi
  568.         if [ \"$sync_binlog\" = 0 ] ; then
  569.             cecho \"Binlog sync is not enabled, you could loose binlog records during a server crash\" red
  570.         fi
  571.     else
  572.         cechon \"The binary update log is \"
  573.         cechon \"NOT \" boldred
  574.         cecho \"enabled.\"
  575.         cecho \"You will not be able to do point in time recovery\" red
  576.         cecho \"See http://dev.mysql.com/doc/refman/$major_version/en/point-in-time-recovery.html\" yellow
  577.     fi
  578. }

  579. check_used_connections () {

  580. ## -- Used Connections -- ##

  581.     mysql_variable \\\'max_connections\\\' max_connections
  582.     mysql_status \\\'Max_used_connections\\\' max_used_connections
  583.     mysql_status \\\'Threads_connected\\\' threads_connected

  584.     connections_ratio=$(($max_used_connections*100/$max_connections))

  585.     cecho \"MAX CONNECTIONS\" boldblue
  586.     cecho \"Current max_connections = $max_connections\"
  587.     cecho \"Current threads_connected = $threads_connected\"
  588.     cecho \"Historic max_used_connections = $max_used_connections\"
  589.     cechon \"The number of used connections is \"
  590.     if [ $connections_ratio -ge 85 ] ; then
  591.         txt_color=red
  592.         error=1
  593.     elif [ $connections_ratio -le 10 ] ; then
  594.         txt_color=red
  595.         error=2
  596.     else
  597.         txt_color=green
  598.         error=0
  599.     fi
  600.     # cechon \"$max_used_connections \" $txt_color
  601.     # cechon \"which is \"
  602.     cechon \"$connections_ratio% \" $txt_color
  603.     cecho \"of the configured maximum.\"

  604.     if [ $error -eq 1 ] ; then
  605.         cecho \"You should raise max_connections\" $txt_color
  606.     elif [ $error -eq 2 ] ; then
  607.         cecho \"You are using less than 10% of your configured max_connections.\" $txt_color
  608.         cecho \"Lowering max_connections could help to avoid an over-allocation of memory\" $txt_color
  609.         cecho \"See \\\"MEMORY USAGE\\\" section to make sure you are not over-allocating\" $txt_color
  610.     else
  611.         cecho \"Your max_connections variable seems to be fine.\" $txt_color
  612.     fi
  613.     unset txt_color
  614. }

  615. check_threads() {

  616. ## -- Worker Threads -- ##

  617.     cecho \"WORKER THREADS\" boldblue

  618.     mysql_status \\\'Threads_created\\\' threads_created1
  619.     sleep 1
  620.     mysql_status \\\'Threads_created\\\' threads_created2

  621.     mysql_status \\\'Threads_cached\\\' threads_cached
  622.     mysql_status \\\'Uptime\\\' uptime
  623.     mysql_variable \\\'thread_cache_size\\\' thread_cache_size

  624.     historic_threads_per_sec=$(($threads_created1/$uptime))
  625.     current_threads_per_sec=$(($threads_created2-$threads_created1))

  626.     cecho \"Current thread_cache_size = $thread_cache_size\"
  627.     cecho \"Current threads_cached = $threads_cached\"
  628.     cecho \"Current threads_per_sec = $current_threads_per_sec\"
  629.     cecho \"Historic threads_per_sec = $historic_threads_per_sec\"

  630.     if [ $historic_threads_per_sec -ge 2 ] && [ $threads_cached -le 1 ] ; then
  631.         cecho \"Threads created per/sec are overrunning threads cached\" red
  632.         cecho \"You should raise thread_cache_size\" red
  633.     elif [ $current_threads_per_sec -ge 2 ] ; then
  634.         cecho \"Threads created per/sec are overrunning threads cached\" red
  635.         cecho \"You should raise thread_cache_size\" red
  636.     else
  637.         cecho \"Your thread_cache_size is fine\" green
  638.     fi
  639. }

  640. check_key_buffer_size () {

  641. ## -- Key buffer Size -- ##

  642.     cecho \"KEY BUFFER\" boldblue

  643.     mysql_status \\\'Key_read_requests\\\' key_read_requests
  644.     mysql_status \\\'Key_reads\\\' key_reads
  645.     mysql_status \\\'Key_blocks_used\\\' key_blocks_used
  646.     mysql_status \\\'Key_blocks_unused\\\' key_blocks_unused
  647.     mysql_variable \\\'key_cache_block_size\\\' key_cache_block_size
  648.     mysql_variable \\\'key_buffer_size\\\' key_buffer_size
  649.         mysql_variable \\\'datadir\\\' datadir
  650.         mysql_variable \\\'version_compile_machine\\\' mysql_version_compile_machine
  651.     myisam_indexes=$($mysql -Bse \"/*!50000 SELECT IFNULL(SUM(INDEX_LENGTH),0) from information_schema.TABLES where ENGINE=\'MyISAM\' */\")

  652.     if [ -z $myisam_indexes ] ; then
  653.         myisam_indexes=$(find $datadir -name \'*.MYI\' -exec du $duflags \'{}\' \\; 2>&1 | awk \'{ s += $1 } END { printf(\"%.0f\\n\", s )}\')
  654.     fi

  655.         if [ $key_reads -eq 0 ] ; then
  656.                 cecho \"No key reads?!\" boldred
  657.                 cecho \"Seriously look into using some indexes\" red
  658.                 key_cache_miss_rate=0
  659.                 key_buffer_free=$(echo \"$key_blocks_unused * $key_cache_block_size / $key_buffer_size * 100\" | bc -l )
  660.                 key_buffer_freeRND=$(echo \"scale=0; $key_buffer_free / 1\" | bc -l)
  661.         else
  662.                 key_cache_miss_rate=$(($key_read_requests/$key_reads))
  663.                 if [ ! -z $key_blocks_unused ] ; then
  664.             key_buffer_free=$(echo \"$key_blocks_unused * $key_cache_block_size / $key_buffer_size * 100\" | bc -l )
  665.                     key_buffer_freeRND=$(echo \"scale=0; $key_buffer_free / 1\" | bc -l)
  666.                 else
  667.                         key_buffer_free=\'Unknown\'
  668.                         key_buffer_freeRND=75
  669.                 fi
  670.         fi

  671.     human_readable $myisam_indexes myisam_indexesHR
  672.     cecho \"Current MyISAM index space = $myisam_indexesHR $unit\"

  673.     human_readable $key_buffer_size key_buffer_sizeHR
  674.     cecho \"Current key_buffer_size = $key_buffer_sizeHR $unit\"
  675.     cecho \"Key cache miss rate is 1 : $key_cache_miss_rate\"
  676.     cecho \"Key buffer free ratio = $key_buffer_freeRND %\"

  677.     if [ \"$major_version\" = \'5.1\' ] && [ $mysql_version_num -lt 050123 ] ; then
  678.         if [ $key_buffer_size -ge 4294967296 ] && ( echo \"x86_64 ppc64 ia64 sparc64 i686\" | grep -q $mysql_version_compile_machine ) ; then
  679.             cecho \"Using key_buffer_size > 4GB will cause instability in versions prior to 5.1.23 \" boldred
  680.             cecho \"See Bug#5731, Bug#29419, Bug#29446\" boldred
  681.         fi
  682.     fi
  683.     if [ \"$major_version\" = \'5.0\' ] && [ $mysql_version_num -lt 050052 ] ; then
  684.         if [ $key_buffer_size -ge 4294967296 ] && ( echo \"x86_64 ppc64 ia64 sparc64 i686\" | grep -q $mysql_version_compile_machine ) ; then
  685.             cecho \"Using key_buffer_size > 4GB will cause instability in versions prior to 5.0.52 \" boldred
  686.             cecho \"See Bug#5731, Bug#29419, Bug#29446\" boldred
  687.         fi
  688.     fi
  689.     if [ \"$major_version\" = \'4.1\' -o \"$major_version\" = \'4.0\' ] && [ $key_buffer_size -ge 4294967296 ] && ( echo \"x86_64 ppc64 ia64 sparc64 i686\" | grep -q $mysql_version_compile_machine ) ; then
  690.         cecho \"Using key_buffer_size > 4GB will cause instability in versions prior to 5.0.52 \" boldred
  691.         cecho \"Reduce key_buffer_size to a safe value\" boldred
  692.         cecho \"See Bug#5731, Bug#29419, Bug#29446\" boldred
  693.     fi

  694.     if [ $key_cache_miss_rate -le 100 ] && [ $key_cache_miss_rate -gt 0 ] && [ $key_buffer_freeRND -le 20 ]; then
  695.         cecho \"You could increase key_buffer_size\" boldred
  696.         cecho \"It is safe to raise this up to 1/4 of total system memory;\"
  697.         cecho \"assuming this is a dedicated database server.\"
  698.     elif [ $key_buffer_freeRND -le 20 ] && [ $key_buffer_size -le $myisam_indexes ] ; then
  699.         cecho \"You could increase key_buffer_size\" boldred
  700.         cecho \"It is safe to raise this up to 1/4 of total system memory;\"
  701.         cecho \"assuming this is a dedicated database server.\"
  702.     elif [ $key_cache_miss_rate -ge 10000 ] || [ $key_buffer_freeRND -le 50 ] ; then
  703.         cecho \"Your key_buffer_size seems to be too high.\" red
  704.         cecho \"Perhaps you can use these resources elsewhere\" red
  705.     else
  706.         cecho \"Your key_buffer_size seems to be fine\" green
  707.     fi
  708. }

  709. check_query_cache () {

  710. ## -- Query Cache -- ##

  711.     cecho \"QUERY CACHE\" boldblue

  712.     mysql_variable \\\'version\\\' mysql_version
  713.     mysql_variable \\\'query_cache_size\\\' query_cache_size
  714.     mysql_variable \\\'query_cache_limit\\\' query_cache_limit
  715.     mysql_variable \\\'query_cache_min_res_unit\\\' query_cache_min_res_unit
  716.     mysql_status \\\'Qcache_free_memory\\\' qcache_free_memory
  717.     mysql_status \\\'Qcache_total_blocks\\\' qcache_total_blocks
  718.     mysql_status \\\'Qcache_free_blocks\\\' qcache_free_blocks
  719.     mysql_status \\\'Qcache_lowmem_prunes\\\' qcache_lowmem_prunes

  720.     if [ -z $query_cache_size ] ; then
  721.         cecho \"You are using MySQL $mysql_version, no query cache is supported.\" red
  722.         cecho \"I recommend an upgrade to MySQL 4.1 or better\" red
  723.     elif [ $query_cache_size -eq 0 ] ; then
  724.         cecho \"Query cache is supported but not enabled\" red
  725.         cecho \"Perhaps you should set the query_cache_size\" red
  726.     else
  727.         qcache_used_memory=$(($query_cache_size-$qcache_free_memory))
  728.         qcache_mem_fill_ratio=$(echo \"scale=2; $qcache_used_memory * 100 / $query_cache_size\" | bc -l)
  729.         qcache_mem_fill_ratioHR=$(echo \"scale=0; $qcache_mem_fill_ratio / 1\" | bc -l)

  730.         cecho \"Query cache is enabled\" green
  731.         human_readable $query_cache_size query_cache_sizeHR
  732.         cecho \"Current query_cache_size = $query_cache_sizeHR $unit\"
  733.         human_readable $qcache_used_memory qcache_used_memoryHR
  734.         cecho \"Current query_cache_used = $qcache_used_memoryHR $unit\"
  735.         human_readable $query_cache_limit query_cache_limitHR
  736.         cecho \"Current query_cache_limit = $query_cache_limitHR $unit\"
  737.         cecho \"Current Query cache Memory fill ratio = $qcache_mem_fill_ratio %\"
  738.         if [ -z $query_cache_min_res_unit ] ; then
  739.             cecho \"No query_cache_min_res_unit is defined. Using MySQL < 4.1 cache fragmentation can be inpredictable\" %yellow
  740.         else
  741.             human_readable $query_cache_min_res_unit query_cache_min_res_unitHR
  742.             cecho \"Current query_cache_min_res_unit = $query_cache_min_res_unitHR $unit\"
  743.         fi
  744.         if [ $qcache_free_blocks -gt 2 ] && [ $qcache_total_blocks -gt 0 ] ; then
  745.             qcache_percent_fragmented=$(echo \"scale=2; $qcache_free_blocks * 100 / $qcache_total_blocks\" | bc -l)
  746.             qcache_percent_fragmentedHR=$(echo \"scale=0; $qcache_percent_fragmented / 1\" | bc -l)
  747.             if [ $qcache_percent_fragmentedHR -gt 20 ] ; then
  748.                 cecho \"Query Cache is $qcache_percent_fragmentedHR % fragmented\" red
  749.                 cecho \"Run \\\"FLUSH QUERY CACHE\\\" periodically to defragment the query cache memory\" red
  750.                 cecho \"If you have many small queries lower \'query_cache_min_res_unit\' to reduce fragmentation.\" red
  751.             fi
  752.         fi

  753.         if [ $qcache_mem_fill_ratioHR -le 25 ] ; then
  754.              cecho \"Your query_cache_size seems to be too high.\" red
  755.      cecho \"Perhaps you can use these resources elsewhere\" red
  756.         fi
  757.         if [ $qcache_lowmem_prunes -ge 50 ] && [ $qcache_mem_fill_ratioHR -ge 80 ]; then
  758.             cechon \"However, \"
  759.             cechon \"$qcache_lowmem_prunes \" boldred
  760.             cecho \"queries have been removed from the query cache due to lack of memory\"
  761.             cecho \"Perhaps you should raise query_cache_size\" boldred
  762.         fi
  763.         cecho \"MySQL won\'t cache query results that are larger than query_cache_limit in size\" yellow
  764.     fi

  765. }

  766. check_sort_operations () {

  767. ## -- Sort Operations -- ##

  768.     cecho \"SORT OPERATIONS\" boldblue

  769.     mysql_status \\\'Sort_merge_passes\\\' sort_merge_passes
  770.     mysql_status \\\'Sort_scan\\\' sort_scan
  771.     mysql_status \\\'Sort_range\\\' sort_range
  772.     mysql_variable \\\'sort_buffer%\\\' sort_buffer_size
  773.     mysql_variable \\\'read_rnd_buffer_size\\\' read_rnd_buffer_size

  774.     total_sorts=$(($sort_scan+$sort_range))
  775.     if [ -z $read_rnd_buffer_size ] ; then
  776.         mysql_variable \\\'record_buffer\\\' read_rnd_buffer_size
  777.     fi

  778.     ## Correct for rounding error in mysqld where 512K != 524288 ##
  779.     sort_buffer_size=$(($sort_buffer_size+8))
  780.     read_rnd_buffer_size=$(($read_rnd_buffer_size+8))

  781.     human_readable $sort_buffer_size sort_buffer_sizeHR
  782.     cecho \"Current sort_buffer_size = $sort_buffer_sizeHR $unit\"

  783.     human_readable $read_rnd_buffer_size read_rnd_buffer_sizeHR
  784.     cechon \"Current \"
  785.     if [ \"$major_version\" = \'3.23\' ] ; then
  786.         cechon \"record_rnd_buffer \"
  787.     else
  788.         cechon \"read_rnd_buffer_size \"
  789.     fi
  790.     cecho \"= $read_rnd_buffer_sizeHR $unit\"

  791.     if [ $total_sorts -eq 0 ] ; then
  792.         cecho \"No sort operations have been performed\"
  793.         passes_per_sort=0
  794.     fi
  795.     if [ $sort_merge_passes -ne 0 ] ; then
  796.         passes_per_sort=$(($sort_merge_passes/$total_sorts))
  797.     else
  798.         passes_per_sort=0
  799.     fi

  800.     if [ $passes_per_sort -ge 2 ] ; then
  801.         cechon \"On average \"
  802.         cechon \"$passes_per_sort \" boldred
  803.         cecho \"sort merge passes are made per sort operation\"
  804.         cecho \"You should raise your sort_buffer_size\"
  805.         cechon \"You should also raise your \"
  806.         if [ \"$major_version\" = \'3.23\' ] ; then
  807.             cecho \"record_rnd_buffer_size\"
  808.         else
  809.             cecho \"read_rnd_buffer_size\"
  810.         fi
  811.     else
  812.         cecho \"Sort buffer seems to be fine\" green
  813.     fi
  814. }

  815. check_join_operations () {

  816. ## -- Joins -- ##

  817.     cecho \"JOINS\" boldblue

  818.     mysql_status \\\'Select_full_join\\\' select_full_join
  819.     mysql_status \\\'Select_range_check\\\' select_range_check
  820.     mysql_variable \\\'join_buffer%\\\' join_buffer_size
  821.     
  822.     ## Some 4K is dropped from join_buffer_size adding it back to make sane ##
  823.     ## handling of human-readable conversion ##

  824.     join_buffer_size=$(($join_buffer_size+4096))

  825.     human_readable $join_buffer_size join_buffer_sizeHR 2

  826.     cecho \"Current join_buffer_size = $join_buffer_sizeHR $unit\"
  827.     cecho \"You have had $select_full_join queries where a join could not use an index properly\"

  828.     if [ $select_range_check -eq 0 ] && [ $select_full_join -eq 0 ] ; then
  829.         cecho \"Your joins seem to be using indexes properly\" green
  830.     fi
  831.     if [ $select_full_join -gt 0 ] ; then
  832.         print_error=\'true\'
  833.         raise_buffer=\'true\'
  834.     fi
  835.     if [ $select_range_check -gt 0 ] ; then
  836.         cecho \"You have had $select_range_check joins without keys that check for key usage after each row\" red
  837.         print_error=\'true\'
  838.         raise_buffer=\'true\'
  839.     fi

  840.     ## For Debuging ##
  841.     # print_error=\'true\'
  842.     if [ $join_buffer_size -ge 4194304 ] ; then
  843.         cecho \"join_buffer_size >= 4 M\" boldred
  844.         cecho \"This is not advised\" boldred
  845.         raise_buffer=
  846.     fi

  847.     if [ $print_error ] ; then
  848.         if [ \"$major_version\" = \'3.23\' ] || [ \"$major_version\" = \'4.0\' ] ; then
  849.             cecho \"You should enable \\\"log-long-format\\\" \"
  850.         elif [ \"$mysql_version_num\" -gt 040100 ]; then
  851.             cecho \"You should enable \\\"log-queries-not-using-indexes\\\"\"
  852.         fi
  853.         cecho \"Then look for non indexed joins in the slow query log.\"
  854.         if [ $raise_buffer ] ; then
  855.         cecho \"If you are unable to optimize your queries you may want to increase your\"
  856.         cecho \"join_buffer_size to accommodate larger joins in one pass.\"
  857.         printf \"\\n\"
  858.         cecho \"Note! This script will still suggest raising the join_buffer_size when\" boldred
  859.         cecho \"ANY joins not using indexes are found.\" boldred
  860.         fi
  861.     fi

  862.     # XXX Add better tests for join_buffer_size pending mysql bug #15088 XXX #
  863. }

  864. check_tmp_tables () {

  865. ## -- Temp Tables -- ##

  866.     cecho \"TEMP TABLES\" boldblue

  867.     mysql_status \\\'Created_tmp_tables\\\' created_tmp_tables
  868.     mysql_status \\\'Created_tmp_disk_tables\\\' created_tmp_disk_tables
  869.     mysql_variable \\\'tmp_table_size\\\' tmp_table_size
  870.     mysql_variable \\\'max_heap_table_size\\\' max_heap_table_size


  871.     if [ $created_tmp_tables -eq 0 ] ; then
  872.         tmp_disk_tables=0
  873.     else
  874.         tmp_disk_tables=$((created_tmp_disk_tables*100/(created_tmp_tables+created_tmp_disk_tables)))
  875.     fi
  876.     human_readable $max_heap_table_size max_heap_table_sizeHR
  877.     cecho \"Current max_heap_table_size = $max_heap_table_sizeHR $unit\"

  878.     human_readable $tmp_table_size tmp_table_sizeHR
  879.     cecho \"Current tmp_table_size = $tmp_table_sizeHR $unit\"

  880.     cecho \"Of $created_tmp_tables temp tables, $tmp_disk_tables% were created on disk\"
  881.     if [ $tmp_table_size -gt $max_heap_table_size ] ; then
  882.         cecho \"Effective in-memory tmp_table_size is limited to max_heap_table_size.\" yellow
  883.     fi
  884.     if [ $tmp_disk_tables -ge 25 ] ; then
  885.         cecho \"Perhaps you should increase your tmp_table_size and/or max_heap_table_size\" boldred
  886.         cecho \"to reduce the number of disk-based temporary tables\" boldred
  887.         cecho \"Note! BLOB and TEXT columns are not allow in memory tables.\" yellow
  888.         cecho \"If you are using these columns raising these values might not impact your \" yellow
  889.         cecho \"ratio of on disk temp tables.\" yellow
  890.     else
  891.         cecho \"Created disk tmp tables ratio seems fine\" green
  892.     fi
  893. }

  894. check_open_files () {

  895. ## -- Open Files Limit -- ##
  896.     cecho \"OPEN FILES LIMIT\" boldblue

  897.     mysql_variable \\\'open_files_limit\\\' open_files_limit
  898.     mysql_status \\\'Open_files\\\' open_files
  899.     
  900.     if [ -z $open_files_limit ] || [ $open_files_limit -eq 0 ] ; then
  901.         open_files_limit=$(ulimit -n)
  902.         cant_override=1
  903.     else
  904.         cant_override=0
  905.     fi
  906.     cecho \"Current open_files_limit = $open_files_limit files\"
  907.     
  908.     open_files_ratio=$(($open_files*100/$open_files_limit))

  909.     cecho \"The open_files_limit should typically be set to at least 2x-3x\" yellow
  910.     cecho \"that of table_cache if you have heavy MyISAM usage.\" yellow
  911.     if [ $open_files_ratio -ge 75 ] ; then
  912.         cecho \"You currently have open more than 75% of your open_files_limit\" boldred
  913.         if [ $cant_override -eq 1 ] ; then
  914.             cecho \"You should set a higer value for ulimit -u in the mysql startup script then restart mysqld\" boldred
  915.             cecho \"MySQL 3.23 users : This is just a guess based upon the current shell\'s ulimit -u value\" yellow
  916.         elif [ $cant_override -eq 0 ] ; then
  917.             cecho \"You should set a higher value for open_files_limit in my.cnf\" boldred
  918.         else
  919.             cecho \"ERROR can\'t determine if mysqld override of ulimit is allowed\" boldred
  920.             exit 1
  921.         fi
  922.     else
  923.         cecho \"Your open_files_limit value seems to be fine\" green
  924.     fi

  925.     

  926. }

  927. check_table_cache () {

  928. ## -- Table Cache -- ##

  929.     cecho \"TABLE CACHE\" boldblue

  930.     mysql_variable \\\'datadir\\\' datadir
  931.     mysql_variable \\\'table_cache\\\' table_cache

  932.     ## /* MySQL +5.1 version of table_cache */ ##
  933.     mysql_variable \\\'table_open_cache\\\' table_open_cache
  934.     mysql_variable \\\'table_definition_cache\\\' table_definition_cache

  935.     mysql_status \\\'Open_tables\\\' open_tables
  936.     mysql_status \\\'Opened_tables\\\' opened_tables
  937.     mysql_status \\\'Open_table_definitions\\\' open_table_definitions
  938.  
  939.     table_count=$($mysql -Bse \"/*!50000 SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE=\'BASE TABLE\' */\")

  940.     if [ -z \"$table_count\" ] ; then
  941.         if [ \"$UID\" != \"$socket_owner\" ] && [ \"$UID\" != \"0\" ] ; then
  942.             cecho \"You are not \'$socket_owner\' or \'root\'\" red
  943.             cecho \"I am unable to determine the table_count!\" red
  944.         else
  945.             table_count=$(find $datadir 2>&1 | grep -c .frm$)
  946.         fi
  947.     fi
  948.     if [ $table_open_cache ] ; then
  949.         table_cache=$table_open_cache
  950.     fi

  951.     if [ $opened_tables -ne 0 ] && [ $table_cache -ne 0 ] ; then
  952.         table_cache_hit_rate=$(($open_tables*100/$opened_tables))
  953.         table_cache_fill=$(($open_tables*100/$table_cache))
  954.     elif [ $opened_tables -eq 0 ] && [ $table_cache -ne 0 ] ; then
  955.         table_cache_hit_rate=100
  956.         table_cache_fill=$(($open_tables*100/$table_cache))
  957.     else
  958.         cecho \"ERROR no table_cache ?!\" boldred
  959.         exit 1
  960.     fi
  961.     if [ $table_cache ] && [ ! $table_open_cache ] ; then
  962.         cecho \"Current table_cache value = $table_cache tables\"
  963.     fi
  964.     if [ $table_open_cache ] ; then
  965.         cecho \"Current table_open_cache = $table_open_cache tables\"
  966.         cecho \"Current table_definition_cache = $table_definition_cache tables\"
  967.     fi
  968.     if [ $table_count ] ; then
  969.     cecho \"You have a total of $table_count tables\"
  970.     fi

  971.     if [ $table_cache_fill -lt 95 ] ; then
  972.         cechon \"You have \"
  973.         cechon \"$open_tables \" green
  974.         cecho \"open tables.\"
  975.         cecho \"The table_cache value seems to be fine\" green
  976.     elif [ $table_cache_hit_rate -le 85 -o $table_cache_fill -ge 95 ]; then
  977.         cechon \"You have \"
  978.         cechon \"$open_tables \" boldred
  979.         cecho \"open tables.\"
  980.         cechon \"Current table_cache hit rate is \"
  981.         cecho \"$table_cache_hit_rate%\" boldred
  982.         cechon \", while \"
  983.         cechon \"$table_cache_fill% \" boldred
  984.         cecho \"of your table cache is in use\"
  985.         cecho \"You should probably increase your table_cache\" red
  986.     else
  987.         cechon \"Current table_cache hit rate is \"
  988.         cechon \"$table_cache_hit_rate%\" green
  989.         cechon \", while \"
  990.         cechon \"$table_cache_fill% \" green
  991.         cecho \"of your table cache is in use\"
  992.         cecho \"The table cache value seems to be fine\" green
  993.     fi
  994.     if [ $table_definition_cache ] && [ $table_definition_cache -le $table_count ] && [ $table_count -ge 100 ] ; then
  995.         cecho \"You should probably increase your table_definition_cache value.\" red
  996.     fi
  997. }

  998. check_table_locking () {

  999. ## -- Table Locking -- ##

  1000.     cecho \"TABLE LOCKING\" boldblue

  1001.     mysql_status \\\'Table_locks_waited\\\' table_locks_waited
  1002.     mysql_status \\\'Table_locks_immediate\\\' table_locks_immediate
  1003.     mysql_variable \\\'concurrent_insert\\\' concurrent_insert
  1004.     mysql_variable \\\'low_priority_updates\\\' low_priority_updates
  1005.         if [ \"$concurrent_insert\" = \'ON\' ]; then
  1006.                 concurrent_insert=1
  1007.         elif [ \"$concurrent_insert\" = \'OFF\' ]; then
  1008.                 concurrent_insert=0
  1009.         fi

  1010.     cechon \"Current Lock Wait ratio = \"
  1011.     if [ $table_locks_waited -gt 0 ]; then
  1012.         immediate_locks_miss_rate=$(($table_locks_immediate/$table_locks_waited))
  1013.         cecho \"1 : $immediate_locks_miss_rate\" red
  1014.     else
  1015.         immediate_locks_miss_rate=99999 # perfect
  1016.         cecho \"0 : $questions\"
  1017.     fi
  1018.     if [ $immediate_locks_miss_rate -lt 5000 ] ; then
  1019.         cecho \"You may benefit from selective use of InnoDB.\"
  1020.         if [ \"$low_priority_updates\" = \'OFF\' ] ; then
  1021.         cecho \"If you have long running SELECT\'s against MyISAM tables and perform\"
  1022.         cecho \"frequent updates consider setting \'low_priority_updates=1\'\"
  1023.         fi
  1024.         if [ \"$mysql_version_num\" -gt 050000 ] && [ \"$mysql_version_num\" -lt 050500 ]; then
  1025.             if [ $concurrent_insert -le 1 ] ; then
  1026.             cecho \"If you have a high concurrency of inserts on Dynamic row-length tables\"
  1027.             cecho \"consider setting \'concurrent_insert=2\'.\"
  1028.             fi
  1029.         elif [ \"$mysql_version_num\" -gt 050500 ] ; then
  1030.             if [ \"$concurrent_insert\" = \'AUTO\' ] || [ \"$concurrent_insert\" = \'NEVER\' ] ; then
  1031.             cecho \"If you have a high concurrency of inserts on Dynamic row-length tables\"
  1032.             cecho \"consider setting \'concurrent_insert=ALWAYS\'.\"
  1033.             fi
  1034.         fi
  1035.     else
  1036.         cecho \"Your table locking seems to be fine\" green
  1037.     fi
  1038. }

  1039. check_table_scans () {

  1040. ## -- Table Scans -- ##

  1041.     cecho \"TABLE SCANS\" boldblue

  1042.     mysql_status \\\'Com_select\\\' com_select
  1043.     mysql_status \\\'Handler_read_rnd_next\\\' read_rnd_next
  1044.     mysql_variable \\\'read_buffer_size\\\' read_buffer_size

  1045.     if [ -z $read_buffer_size ] ; then
  1046.         mysql_variable \\\'record_buffer\\\' read_buffer_size
  1047.     fi

  1048.      human_readable $read_buffer_size read_buffer_sizeHR
  1049.     cecho \"Current read_buffer_size = $read_buffer_sizeHR $unit\"
  1050.     
  1051.     if [ $com_select -gt 0 ] ; then
  1052.         full_table_scans=$(($read_rnd_next/$com_select))
  1053.         cecho \"Current table scan ratio = $full_table_scans : 1\"
  1054.         if [ $full_table_scans -ge 4000 ] && [ $read_buffer_size -le 2097152 ] ; then
  1055.             cecho \"You have a high ratio of sequential access requests to SELECTs\" red
  1056.             cechon \"You may benefit from raising \" red
  1057.             if [ \"$major_version\" = \'3.23\' ] ; then
  1058.                 cechon \"record_buffer \" red
  1059.             else
  1060.                 cechon \"read_buffer_size \" red
  1061.             fi
  1062.             cecho \"and/or improving your use of indexes.\" red
  1063.         elif [ $read_buffer_size -gt 8388608 ] ; then
  1064.             cechon \"read_buffer_size is over 8 MB \" red
  1065.             cecho \"there is probably no need for such a large read_buffer\" red
  1066.         
  1067.         else
  1068.             cecho \"read_buffer_size seems to be fine\" green
  1069.         fi
  1070.     else
  1071.         cecho \"read_buffer_size seems to be fine\" green
  1072.     fi
  1073. }


  1074. check_innodb_status () {

  1075. ## -- InnoDB -- ##

  1076.     ## See http://bugs.mysql.com/59393

  1077.     if [ \"$mysql_version_num\" -lt 050603 ] ; then
  1078.     mysql_variable \\\'have_innodb\\\' have_innodb
  1079.     fi
  1080.     if [ \"$mysql_version_num\" -lt 050500 ] && [ \"$have_innodb\" = \"YES\" ] ; then
  1081.     innodb_enabled=1
  1082.     fi
  1083.     if [ \"$mysql_version_num\" -ge 050500 ] && [ \"$mysql_version_num\" -lt 050512 ] ; then
  1084.     mysql_variable \\\'ignore_builtin_innodb\\\' ignore_builtin_innodb
  1085.         if [ \"$ignore_builtin_innodb\" = \"ON\" ] || [ $have_innodb = \"NO\" ] ; then
  1086.         innodb_enabled=0
  1087.         else
  1088.         innodb_enabled=1
  1089.         fi
  1090.     elif [ \"$major_version\" = \'5.5\' ] && [ \"$mysql_version_num\" -ge 050512 ] ; then
  1091.     mysql_variable \\\'ignore_builtin_innodb\\\' ignore_builtin_innodb
  1092.         if [ \"$ignore_builtin_innodb\" = \"ON\" ] ; then
  1093.         innodb_enabled=0
  1094.         else
  1095.         innodb_enabled=1
  1096.         fi
  1097.     elif [ \"$mysql_version_num\" -ge 050600 ] && [ \"$mysql_version_num\" -lt 050603 ] ; then
  1098.     mysql_variable \\\'ignore_builtin_innodb\\\' ignore_builtin_innodb
  1099.         if [ \"$ignore_builtin_innodb\" = \"ON\" ] || [ $have_innodb = \"NO\" ] ; then
  1100.         innodb_enabled=0
  1101.         else
  1102.         innodb_enabled=1
  1103.         fi
  1104.     elif [ \"$major_version\" = \'5.6\' ] && [ \"$mysql_version_num\" -ge 050603 ] ; then
  1105.     mysql_variable \\\'ignore_builtin_innodb\\\' ignore_builtin_innodb
  1106.                 if [ \"$ignore_builtin_innodb\" = \"ON\" ] ; then
  1107.                 innodb_enabled=0
  1108.                 else
  1109.                 innodb_enabled=1
  1110.                 fi
  1111.     fi
  1112.     if [ \"$innodb_enabled\" = 1 ] ; then
  1113.         mysql_variable \\\'innodb_buffer_pool_size\\\' innodb_buffer_pool_size
  1114.         mysql_variable \\\'innodb_additional_mem_pool_size\\\' innodb_additional_mem_pool_size
  1115.         mysql_variable \\\'innodb_fast_shutdown\\\' innodb_fast_shutdown
  1116.         mysql_variable \\\'innodb_flush_log_at_trx_commit\\\' innodb_flush_log_at_trx_commit
  1117.         mysql_variable \\\'innodb_locks_unsafe_for_binlog\\\' innodb_locks_unsafe_for_binlog
  1118.         mysql_variable \\\'innodb_log_buffer_size\\\' innodb_log_buffer_size
  1119.         mysql_variable \\\'innodb_log_file_size\\\' innodb_log_file_size
  1120.         mysql_variable \\\'innodb_log_files_in_group\\\' innodb_log_files_in_group
  1121.         mysql_variable \\\'innodb_safe_binlog\\\' innodb_safe_binlog
  1122.         mysql_variable \\\'innodb_thread_concurrency\\\' innodb_thread_concurrency

  1123.         cecho \"INNODB STATUS\" boldblue
  1124.         innodb_indexes=$($mysql -Bse \"/*!50000 SELECT IFNULL(SUM(INDEX_LENGTH),0) from information_schema.TABLES where ENGINE=\'InnoDB\' */\")
  1125.         innodb_data=$($mysql -Bse \"/*!50000 SELECT IFNULL(SUM(DATA_LENGTH),0) from information_schema.TABLES where ENGINE=\'InnoDB\' */\")
  1126.         
  1127.         if [ ! -z \"$innodb_indexes\" ] ; then

  1128.         mysql_status \\\'Innodb_buffer_pool_pages_data\\\' innodb_buffer_pool_pages_data
  1129.         mysql_status \\\'Innodb_buffer_pool_pages_misc\\\' innodb_buffer_pool_pages_misc
  1130.         mysql_status \\\'Innodb_buffer_pool_pages_free\\\' innodb_buffer_pool_pages_free
  1131.         mysql_status \\\'Innodb_buffer_pool_pages_total\\\' innodb_buffer_pool_pages_total

  1132.         mysql_status \\\'Innodb_buffer_pool_read_ahead_seq\\\' innodb_buffer_pool_read_ahead_seq
  1133.         mysql_status \\\'Innodb_buffer_pool_read_requests\\\' innodb_buffer_pool_read_requests

  1134.         mysql_status \\\'Innodb_os_log_pending_fsyncs\\\' innodb_os_log_pending_fsyncs
  1135.         mysql_status \\\'Innodb_os_log_pending_writes\\\'    innodb_os_log_pending_writes
  1136.         mysql_status \\\'Innodb_log_waits\\\' innodb_log_waits

  1137.         mysql_status \\\'Innodb_row_lock_time\\\' innodb_row_lock_time
  1138.         mysql_status \\\'Innodb_row_lock_waits\\\' innodb_row_lock_waits

  1139.         human_readable $innodb_indexes innodb_indexesHR
  1140.         cecho \"Current InnoDB index space = $innodb_indexesHR $unit\"
  1141.         human_readable $innodb_data innodb_dataHR
  1142.         cecho \"Current InnoDB data space = $innodb_dataHR $unit\"
  1143.         percent_innodb_buffer_pool_free=$(($innodb_buffer_pool_pages_free*100/$innodb_buffer_pool_pages_total))
  1144.         cecho \"Current InnoDB buffer pool free = \"$percent_innodb_buffer_pool_free\" %\"

  1145.         else
  1146.         cecho \"Cannot parse InnoDB stats prior to 5.0.x\" red
  1147.         $mysql -s -e \"SHOW /*!50000 ENGINE */ INNODB STATUS\\G\"
  1148.         fi

  1149.         human_readable $innodb_buffer_pool_size innodb_buffer_pool_sizeHR
  1150.         cecho \"Current innodb_buffer_pool_size = $innodb_buffer_pool_sizeHR $unit\"
  1151.         cecho \"Depending on how much space your innodb indexes take up it may be safe\"
  1152.         cecho \"to increase this value to up to 2 / 3 of total system memory\"
  1153.     else
  1154.         cecho \"No InnoDB Support Enabled!\" boldred
  1155.     fi
  1156. }

  1157. total_memory_used () {

  1158. ## -- Total Memory Usage -- ##
  1159.     cecho \"MEMORY USAGE\" boldblue

  1160.     mysql_variable \\\'read_buffer_size\\\' read_buffer_size
  1161.     mysql_variable \\\'read_rnd_buffer_size\\\' read_rnd_buffer_size
  1162.     mysql_variable \\\'sort_buffer_size\\\' sort_buffer_size
  1163.     mysql_variable \\\'thread_stack\\\' thread_stack
  1164.     mysql_variable \\\'max_connections\\\' max_connections
  1165.     mysql_variable \\\'join_buffer_size\\\' join_buffer_size
  1166.     mysql_variable \\\'tmp_table_size\\\' tmp_table_size
  1167.     mysql_variable \\\'max_heap_table_size\\\' max_heap_table_size
  1168.     mysql_variable \\\'log_bin\\\' log_bin
  1169.     mysql_status \\\'Max_used_connections\\\' max_used_connections

  1170.     if [ \"$major_version\" = \"3.23\" ] ; then
  1171.         mysql_variable \\\'record_buffer\\\' read_buffer_size
  1172.         mysql_variable \\\'record_rnd_buffer\\\' read_rnd_buffer_size
  1173.         mysql_variable \\\'sort_buffer\\\' sort_buffer_size
  1174.     fi

  1175.     if [ \"$log_bin\" = \"ON\" ] ; then
  1176.         mysql_variable \\\'binlog_cache_size\\\' binlog_cache_size
  1177.     else
  1178.         binlog_cache_size=0
  1179.     fi

  1180.     if [ $max_heap_table_size -le $tmp_table_size ] ; then
  1181.         effective_tmp_table_size=$max_heap_table_size
  1182.     else
  1183.         effective_tmp_table_size=$tmp_table_size
  1184.     fi


  1185.     per_thread_buffers=$(echo \"($read_buffer_size+$read_rnd_buffer_size+$sort_buffer_size+$thread_stack+$join_buffer_size+$binlog_cache_size)*$max_connections\" | bc -l)
  1186.     per_thread_max_buffers=$(echo \"($read_buffer_size+$read_rnd_buffer_size+$sort_buffer_size+$thread_stack+$join_buffer_size+$binlog_cache_size)*$max_used_connections\" | bc -l)

  1187.         mysql_variable \\\'innodb_buffer_pool_size\\\' innodb_buffer_pool_size
  1188.         if [ -z $innodb_buffer_pool_size ] ; then
  1189.         innodb_buffer_pool_size=0
  1190.         fi

  1191.         mysql_variable \\\'innodb_additional_mem_pool_size\\\' innodb_additional_mem_pool_size
  1192.         if [ -z $innodb_additional_mem_pool_size ] ; then
  1193.         innodb_additional_mem_pool_size=0
  1194.         fi

  1195.         mysql_variable \\\'innodb_log_buffer_size\\\' innodb_log_buffer_size
  1196.         if [ -z $innodb_log_buffer_size ] ; then
  1197.         innodb_log_buffer_size=0
  1198.         fi

  1199.         mysql_variable \\\'key_buffer_size\\\' key_buffer_size

  1200.         mysql_variable \\\'query_cache_size\\\' query_cache_size
  1201.         if [ -z $query_cache_size ] ; then
  1202.         query_cache_size=0
  1203.         fi

  1204.     global_buffers=$(echo \"$innodb_buffer_pool_size+$innodb_additional_mem_pool_size+$innodb_log_buffer_size+$key_buffer_size+$query_cache_size\" | bc -l)


  1205.     max_memory=$(echo \"$global_buffers+$per_thread_max_buffers\" | bc -l)
  1206.     total_memory=$(echo \"$global_buffers+$per_thread_buffers\" | bc -l)

  1207.     pct_of_sys_mem=$(echo \"scale=0; $total_memory*100/$physical_memory\" | bc -l)

  1208.     if [ $pct_of_sys_mem -gt 90 ] ; then
  1209.         txt_color=boldred
  1210.         error=1
  1211.     else
  1212.         txt_color=
  1213.         error=0
  1214.     fi    

  1215.     human_readable $max_memory max_memoryHR
  1216.     cecho \"Max Memory Ever Allocated : $max_memoryHR $unit\" $txt_color
  1217.     human_readable $per_thread_buffers per_thread_buffersHR
  1218.     cecho \"Configured Max Per-thread Buffers : $per_thread_buffersHR $unit\" $txt_color
  1219.     human_readable $global_buffers global_buffersHR
  1220.     cecho \"Configured Max Global Buffers : $global_buffersHR $unit\" $txt_color
  1221.     human_readable $total_memory total_memoryHR
  1222.     cecho \"Configured Max Memory Limit : $total_memoryHR $unit\" $txt_color
  1223. #    human_readable $effective_tmp_table_size effective_tmp_table_sizeHR
  1224. #    cecho \"Plus $effective_tmp_table_sizeHR $unit per temporary table created\"
  1225.     human_readable $physical_memory physical_memoryHR
  1226.     cecho \"Physical Memory : $physical_memoryHR $unit\" $txt_color
  1227.     if [ $error -eq 1 ] ; then
  1228.         printf \"\\n\"
  1229.         cecho \"Max memory limit exceeds 90% of physical memory\" $txt_color
  1230.     else
  1231.         cecho \"Max memory limit seem to be within acceptable norms\" green
  1232.     fi
  1233.     unset txt_color
  1234. }

  1235. ## Required Functions ##

  1236. login_validation () {
  1237.     check_for_socket         # determine the socket location -- 1st login
  1238.     check_for_plesk_passwords    # determine the login method -- 2nd login
  1239.     check_mysql_login        # determine if mysql is accepting login -- 3rd login
  1240.     export major_version=$($mysql -Bse \"SELECT SUBSTRING_INDEX(VERSION(), \'.\', +2)\")
  1241. #    export mysql_version_num=$($mysql -Bse \"SELECT LEFT(REPLACE(SUBSTRING_INDEX(VERSION(), \'-\', +1), \'.\', \'\'),4)\" )
  1242.     export mysql_version_num=$($mysql -Bse \"SELECT VERSION()\" |
  1243.         awk -F \\. \'{ printf \"%02d\", $1; printf \"%02d\", $2; printf \"%02d\", $3 }\')

  1244. }

  1245. shared_info () {
  1246.     export major_version=$($mysql -Bse \"SELECT SUBSTRING_INDEX(VERSION(), \'.\', +2)\")
  1247.     # export mysql_version_num=$($mysql -Bse \"SELECT LEFT(REPLACE(SUBSTRING_INDEX(VERSION(), \'-\', +1), \'.\', \'\'),4)\" )
  1248.     export mysql_version_num=$($mysql -Bse \"SELECT VERSION()\" |
  1249.         awk -F \\. \'{ printf \"%02d\", $1; printf \"%02d\", $2; printf \"%02d\", $3 }\')
  1250.     mysql_status \\\'Questions\\\' questions
  1251. #    socket_owner=$(find -L $socket -printf \'%u\\n\')
  1252.     socket_owner=$(ls -nH $socket | awk \'{ print $3 }\')
  1253. }
  1254.     

  1255. get_system_info () {

  1256.     export OS=$(uname)
  1257.     
  1258.     # Get information for various UNIXes
  1259.     if [ \"$OS\" = \'Darwin\' ]; then
  1260.     ps_socket=$(netstat -ln | awk \'/mysql(.*)?\\.sock/ { print $9 }\' | head -1)
  1261.     found_socks=$(netstat -ln | awk \'/mysql(.*)?\\.sock/ { print $9 }\')
  1262.         export physical_memory=$(sysctl -n hw.memsize)
  1263.     export duflags=\'\'
  1264.     elif [ \"$OS\" = \'FreeBSD\' ] || [ \"$OS\" = \'OpenBSD\' ]; then
  1265.     ## On FreeBSD must be root to locate sockets.
  1266.     ps_socket=$(netstat -ln | awk \'/mysql(.*)?\\.sock/ { print $9 }\' | head -1)
  1267.     found_socks=$(netstat -ln | awk \'/mysql(.*)?\\.sock/ { print $9 }\')
  1268.         export physical_memory=$(sysctl -n hw.realmem)
  1269.     export duflags=\'\'
  1270.     elif [ \"$OS\" = \'Linux\' ] ; then
  1271.     ## Includes SWAP
  1272.         ## export physical_memory=$(free -b | grep -v buffers | awk \'{ s += $2 } END { printf(\"%.0f\\n\", s ) }\')
  1273.     ps_socket=$(netstat -ln | awk \'/mysql(.*)?\\.sock/ { print $9 }\' | head -1)
  1274.     found_socks=$(netstat -ln | awk \'/mysql(.*)?\\.sock/ { print $9 }\')
  1275.     export physical_memory=$(awk \'/^MemTotal/ { printf(\"%.0f\", $2*1024 ) }\' < /proc/meminfo)
  1276.     export duflags=\'-b\'
  1277.     elif [ \"$OS\" = \'SunOS\' ] ; then
  1278.     ps_socket=$(netstat -an | awk \'/mysql(.*)?.sock/ { print $5 }\' | head -1)
  1279.     found_socks=$(netstat -an | awk \'/mysql(.*)?.sock/ { print $5 }\')
  1280.     export physical_memory=$(prtconf | awk \'/^Memory\\ size:/ { print $3*1048576 }\')
  1281.     fi
  1282.     if [ -z $(which bc) ] ; then
  1283.     echo \"Error: Command line calculator \'bc\' not found!\"
  1284.     exit
  1285.     fi
  1286. }


  1287. ## Optional Components Groups ##

  1288. banner_info () {
  1289.     shared_info
  1290.     print_banner        ; echo
  1291.     check_mysql_version    ; echo
  1292.     post_uptime_warning    ; echo
  1293. }

  1294. misc () {
  1295.     shared_info
  1296.     check_slow_queries    ; echo
  1297.     check_binary_log    ; echo
  1298.     check_threads        ; echo
  1299.     check_used_connections    ; echo
  1300.     check_innodb_status    ; echo
  1301. }

  1302. memory () {
  1303.     shared_info
  1304.     total_memory_used    ; echo
  1305.     check_key_buffer_size    ; echo
  1306.     check_query_cache    ; echo
  1307.     check_sort_operations    ; echo
  1308.     check_join_operations    ; echo
  1309. }

  1310. file () {
  1311.     shared_info
  1312.     check_open_files    ; echo
  1313.     check_table_cache    ; echo
  1314.     check_tmp_tables    ; echo
  1315.     check_table_scans    ; echo
  1316.     check_table_locking    ; echo
  1317. }

  1318. all () {
  1319.     banner_info
  1320.     misc
  1321.     memory
  1322.     file
  1323. }

  1324. prompt () {
  1325.     prompted=\'true\'
  1326.     read -p \"Username [anonymous] : \" user
  1327.     read -rp \"Password [] : \" pass
  1328.     cecho \" \"
  1329.     read -p \"Socket [ /var/lib/mysql/mysql.sock ] : \" socket
  1330.     if [ -z $socket ] ; then
  1331.         export socket=\'/var/lib/mysql/mysql.sock\'
  1332.     fi

  1333.     if [ -z $pass ] ; then
  1334.     export mysql=\"mysql -S $socket -u$user\"
  1335.     export mysqladmin=\"mysqladmin -S $socket -u$user\"
  1336.     else
  1337.         export mysql=\"mysql -S $socket -u$user -p$pass\"
  1338.         export mysqladmin=\"mysqladmin -S $socket -u$user -p$pass\"
  1339.     fi

  1340.     check_for_socket
  1341.     check_mysql_login

  1342.     if [ $? = 1 ] ; then
  1343.         exit 1
  1344.     fi
  1345.     read -p \"Mode to test - banner, file, misc, mem, innodb, [all] : \" REPLY
  1346.     if [ -z $REPLY ] ; then
  1347.         REPLY=\'all\'
  1348.     fi
  1349.     case $REPLY in
  1350.      banner | BANNER | header | HEADER | head | HEAD)
  1351.         banner_info
  1352.         ;;
  1353.         misc | MISC | miscelaneous )
  1354.         misc
  1355.         ;;
  1356.             mem | memory | MEM | MEMORY )
  1357.         memory
  1358.         ;;
  1359.         file | FILE | disk | DISK )
  1360.         file
  1361.         ;;
  1362.         innodb | INNODB )
  1363.         innodb
  1364.         ;;
  1365.         all | ALL )
  1366.         cecho \" \"
  1367.         all
  1368.         ;;
  1369.         * )
  1370.         cecho \"Invalid Mode! Valid options are \'banner\', \'misc\', \'memory\', \'file\', \'innodb\' or \'all\'\" boldred
  1371.         exit 1
  1372.         ;;
  1373.     esac
  1374. }

  1375. ## Address environmental differences ##
  1376. get_system_info
  1377. # echo $ps_socket

  1378. if [ -z \"$1\" ] ; then
  1379.     login_validation
  1380.     mode=\'ALL\'
  1381. elif [ \"$1\" = \"prompt\" ] || [ \"$1\" = \"PROMPT\" ] ; then
  1382.     mode=$1
  1383. elif [ \"$1\" != \"prompt\" ] || [ \"$1\" != \"PROMPT\" ] ; then
  1384.     login_validation
  1385.     mode=$1
  1386. fi

  1387. case $mode in
  1388.     all | ALL )
  1389.     cecho \" \"
  1390.     all
  1391.     ;;
  1392.     mem | memory | MEM | MEMORY )
  1393.     cecho \" \"
  1394.     memory
  1395.     ;;
  1396.     file | FILE | disk | DISK )
  1397.     cecho \" \"
  1398.     file
  1399.     ;;
  1400.     banner | BANNER | header | HEADER | head | HEAD )
  1401.     banner_info
  1402.     ;;
  1403.     misc | MISC | miscelaneous )
  1404.     cecho \" \"
  1405.     misc
  1406.     ;;
  1407.     innodb | INNODB )
  1408.     banner_info
  1409.     check_innodb_status ; echo
  1410.     ;;
  1411.     prompt | PROMPT )
  1412.     prompt
  1413.     ;;
  1414.     *)
  1415.     cecho \"usage: $0 [ all | banner | file | innodb | memory | misc | prompt ]\" boldred
  1416.     exit 1
  1417.     ;;
  1418. esac



来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/29500582/viewspace-1431201/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: Linux系统磁盘IO
请登录后发表评论 登录
全部评论

注册时间:2014-02-22

  • 博文量
    326
  • 访问量
    2671972