Mysql效能檢測指令碼tuning-primer.sh 使用

dbasdk發表於2014-09-25
Mysql效能檢測指令碼tuning-primer.sh 使用


tuning-primer.sh 指令碼說明:
Slow Query Log (慢查詢日誌)  
Max Connections (最大連線數)  
Worker Threads (工作執行緒) 
key Buffer (key 緩衝)  
Query Cache (查詢快取)  
Sort Buffer (排序快取)  
Joins (連線)  
Temp Tables (臨時表)  
Table (Open & Definition) Cache (表快取)  
Table Locking (表鎖定)  
Table Scans (read_buffer) (表掃描,讀緩衝)  
Innodb Status (Innodb 狀態)

點選(此處)摺疊或開啟
[root@sz]# ./tuning-primmer.sh 



    1. Using login values from ~/.my.cnf
      - INITIAL LOGIN ATTEMPT FAILED -
      Testing for stored webmin passwords:
       None Found
      Could not auto detect login info!
      Found Sockets: /var/lib/mysql/mysql.sock
      Using: /var/lib/mysql/mysql.sock
      Would you like to provide a different socket?: [y/N] n
      Do you have your login handy ? [y/N] : y
      User: root
      Password: 123456
      Would you like me to create a ~/.my.cnf file for you? [y/N] : n

  1. SLOW QUERIES
  2. The slow query log is NOT enabled.
  3. Current long_query_time = 10.000000 sec.
  4. You have 46 out of 106839465 that take longer than 10.000000 sec. to complete
  5. Your long_query_time seems to be fine

  6. BINARY UPDATE LOG
  7. The binary update log is NOT enabled.
  8. You will not be able to do point in time recovery
  9. See http://dev.mysql.com/doc/refman/5.1/en/point-in-time-recovery.html

  10. WORKER THREADS
  11. Current thread_cache_size = 0
  12. Current threads_cached = 0
  13. Current threads_per_sec = 5
  14. Historic threads_per_sec = 4
  15. Threads created per/sec are overrunning threads cached
  16. You should raise thread_cache_size

  17. MAX CONNECTIONS
  18. Current max_connections = 5000
  19. Current threads_connected = 32
  20. Historic max_used_connections = 115
  21. The number of used connections is 2% of the configured maximum.
  22. You are using less than 10% of your configured max_connections.
  23. Lowering max_connections could help to avoid an over-allocation of memory
  24. See \"MEMORY USAGE\" section to make sure you are not over-allocating

  25. INNODB STATUS
  26. Current InnoDB index space = 193 M
  27. Current InnoDB data space = 1.34 G
  28. Current InnoDB buffer pool free = 68 %
  29. Current innodb_buffer_pool_size = 4.00 G
  30. Depending on how much space your innodb indexes take up it may be safe
  31. to increase this value to up to 2 / 3 of total system memory

  32. MEMORY USAGE
  33. Max Memory Ever Allocated : 4.31 G
  34. Configured Max Per-thread Buffers : 13.42 G
  35. Configured Max Global Buffers : 4.00 G
  36. Configured Max Memory Limit : 17.43 G
  37. Physical Memory : 15.70 G

  38. nMax memory limit exceeds 90% of physical memory

  39. KEY BUFFER
  40. Current MyISAM index space = 23.01 G
  41. Current key_buffer_size = 7 M
  42. Key cache miss rate is 1 : 16
  43. Key buffer free ratio = 79 %
  44. Your key_buffer_size seems to be fine

  45. QUERY CACHE
  46. Query cache is supported but not enabled
  47. Perhaps you should set the query_cache_size

  48. SORT OPERATIONS
  49. Current sort_buffer_size = 2 M
  50. Current read_rnd_buffer_size = 256 K
  51. Sort buffer seems to be fine

  52. JOINS
  53. Current join_buffer_size = 132.00 K
  54. You have had 859818 queries where a join could not use an index properly
  55. You should enable \"log-queries-not-using-indexes\"
  56. Then look for non indexed joins in the slow query log.
  57. If you are unable to optimize your queries you may want to increase your
  58. join_buffer_size to accommodate larger joins in one pass.

  59.  This script will still suggest raising the join_buffer_size when
  60. ANY joins not using indexes are found.

  61. OPEN FILES LIMIT
  62. Current open_files_limit = 25000 files
  63. The open_files_limit should typically be set to at least 2x-3x
  64. that of table_cache if you have heavy MyISAM usage.
  65. Your open_files_limit value seems to be fine

  66. TABLE CACHE
  67. Current table_open_cache = 64 tables
  68. Current table_definition_cache = 256 tables
  69. You have a total of 436 tables
  70. You have 64 open tables.
  71. Current table_cache hit rate is 0%
  72. , while 100% of your table cache is in use
  73. You should probably increase your table_cache
  74. You should probably increase your table_definition_cache value.

  75. TEMP TABLES
  76. Current max_heap_table_size = 16 M
  77. Current tmp_table_size = 16 M
  78. Of 952404 temp tables, 0% were created on disk
  79. Created disk tmp tables ratio seems fine

  80. TABLE SCANS
  81. Current read_buffer_size = 128 K
  82. Current table scan ratio = 12392 : 1
  83. You have a high ratio of sequential access requests to SELECTs
  84. You may benefit from raising read_buffer_size and/or improving your use of indexes.

  85. TABLE LOCKING
  86. Current Lock Wait ratio = 1 : 9025
  87. Your table locking seems to be fine




tuning-primer.sh 指令碼程式碼:

點選(此處)摺疊或開啟

  1. #!/bin/sh

  2. #########################################################################
  3. #                                    #
  4. #    MySQL performance tuning primer script                #
  5. #    Writen by: Matthew Montgomery <mmontgomery@mysql.com>        #
  6. #    Inspired by: MySQLARd (http://gert.sos.be/demo/mysqlar/)    #
  7. #    Version: 1.5-r5        Released: 2009-11-22            #
  8. #    Licenced under GPLv2 #
  9. #                                    #
  10. #########################################################################

  11. #########################################################################
  12. #                                    #
  13. # Little known feature: 1st argument is execution mode            #
  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=/var/lib/mysql/mysql.sock

  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.     # Color-echo.
  56.     # Argument $1 = message
  57.     # Argument $2 = color
  58. {
  59. local default_msg=\"No message passed.\"

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

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

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

  97. return
  98. }


  99. cechon ()        

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

  101.     # Color-echo.
  102.     # Argument $1 = message
  103.     # Argument $2 = color
  104. {
  105. local default_msg=\"No message passed.\"
  106.                 # Doesn\'t really need to be a local variable.

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

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

  111. case $color in
  112.     black)
  113.          printf \"$black\" ;;
  114.     boldblack)
  115.          printf \"$boldblack\" ;;
  116.     red)
  117.          printf \"$red\" ;;
  118.     boldred)
  119.          printf \"$boldred\" ;;
  120.     yellow)
  121.          printf \"$yellow\" ;;
  122.     boldyellow)
  123.          printf \"$boldyellow\" ;;
  124.     blue)
  125.          printf \"$blue\" ;;
  126.     boldblue)
  127.          printf \"$boldblue\" ;;
  128.     magenta)
  129.          printf \"$magenta\" ;;
  130.     boldmagenta)
  131.          printf \"$boldmagenta\" ;;
  132.     cyan)
  133.          printf \"$cyan\" ;;
  134.     boldcyan)
  135.          printf \"$boldcyan\" ;;
  136.     white)
  137.          printf \"$white\" ;;
  138.     boldwhite)
  139.          printf \"$boldwhite\" ;;
  140. esac
  141.   printf \"%s\" \"$message\"
  142.   tput sgr0            # Reset to normal.
  143.   printf \"$black\"

  144. return
  145. }


  146. print_banner () {

  147. ## -- Banner -- ##

  148. cecho \"    -- MYSQL PERFORMANCE TUNING PRIMER --\" boldblue
  149. cecho \"     - By: Matthew Montgomery -\" black

  150. }

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

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


  182. check_for_plesk_passwords () {

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

  184.     if [ -f /etc/psa/.psa.shadow ] ; then
  185.      mysql=\"mysql -S $socket -u admin -p$(cat /etc/psa/.psa.shadow)\"
  186.      mysqladmin=\"mysqladmin -S $socket -u admin -p$(cat /etc/psa/.psa.shadow)\"
  187.     else
  188.      mysql=\"mysql\"
  189.      mysqladmin=\"mysqladmin\"
  190.      # mysql=\"mysql -S $socket\"
  191.      # mysqladmin=\"mysqladmin -S $socket\"
  192.     fi
  193. }

  194. check_mysql_login () {

  195. ## -- Test for running mysql -- ##

  196.     is_up=$($mysqladmin ping 2>&1)
  197.     if [ \"$is_up\" = \"mysqld is alive\" ] ; then
  198.         echo UP > /dev/null
  199.          # echo $is_up
  200.     elif [ \"$is_up\" != \"mysqld is alive\" ] ; then
  201.         printf \"\\n\"
  202.         cecho \"Using login values from ~/.my.cnf\"
  203.         cecho \"- INITIAL LOGIN ATTEMPT FAILED -\" boldred
  204.         if [ -z $prompted ] ; then
  205.         find_webmin_passwords
  206.         else
  207.             return 1
  208.         fi
  209.         
  210.     else
  211.         cecho \"Unknow exit status\" red
  212.         exit -1
  213.     fi
  214. }

  215. final_login_attempt () {
  216.         is_up=$($mysqladmin ping 2>&1)
  217.         if [ \"$is_up\" = \"mysqld is alive\" ] ; then
  218.                 echo UP > /dev/null
  219.         elif [ \"$is_up\" != \"mysqld is alive\" ] ; then
  220.                 cecho \"- FINAL LOGIN ATTEMPT FAILED -\" boldred
  221.         cecho \"Unable to log into socket: $socket\" boldred
  222.                 exit 1
  223.         fi
  224. }

  225. second_login_failed () {

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

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

  298. find_webmin_passwords () {

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

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

  326. #########################################################################
  327. #                                    #
  328. # Function to pull MySQL status variable                #
  329. #                                    #
  330. # Call using :                                #
  331. #    mysql_status \\\'Mysql_status_variable\\\' bash_dest_variable    #
  332. #                                    #
  333. #########################################################################

  334. mysql_status () {
  335.     local status=$($mysql -Bse \"show /*!50000 global */ status like $1\" | awk \'{ print $2 }\')
  336.     export \"$2\"=$status
  337. }

  338. #########################################################################
  339. #                                    #
  340. # Function to pull MySQL server runtime variable            #
  341. #                                    #
  342. # Call using :                                #
  343. #    mysql_variable \\\'Mysql_server_variable\\\' bash_dest_variable    #
  344. #    - OR -                                #
  345. #    mysql_variableTSV \\\'Mysql_server_variable\\\' bash_dest_variable    #
  346. #                                    #
  347. #########################################################################

  348. mysql_variable () {
  349.     local variable=$($mysql -Bse \"show /*!50000 global */ variables like $1\" | awk \'{ print $2 }\')
  350.     export \"$2\"=$variable
  351. }
  352. mysql_variableTSV () {
  353.         local variable=$($mysql -Bse \"show /*!50000 global */ variables like $1\" | awk -F \\t \'{ print $2 }\')
  354.         export \"$2\"=$variable
  355. }

  356. float2int () {
  357.         local variable=$(echo \"$1 / 1\" | bc -l)
  358.         export \"$2\"=$variable
  359. }

  360. divide () {

  361. # -- Divide two intigers -- #

  362.     usage=\"$0 dividend divisor \'$variable\' scale\"
  363.     if [ $1 -ge 1 ]    ; then
  364.         dividend=$1
  365.     else
  366.         cecho \"Invalid Dividend\" red
  367.         echo $usage
  368.         exit 1
  369.     fi
  370.     if [ $2 -ge 1 ] ; then
  371.         divisor=$2
  372.     else
  373.         cecho \"Invalid Divisor\" red
  374.         echo $usage
  375.         exit 1
  376.     fi
  377.     if [ ! -n $3 ] ; then
  378.         cecho \"Invalid variable name\" red
  379.         echo $usage
  380.         exit 1
  381.     fi
  382.     if [ -z $4 ] ; then
  383.         scale=2
  384.     elif [ $4 -ge 0 ] ; then
  385.         scale=$4
  386.     else
  387.         cecho \"Invalid scale\" red
  388.         echo $usage
  389.         exit 1
  390.     fi
  391.     export $3=$(echo \"scale=$scale; $dividend / $divisor\" | bc -l)
  392. }

  393. human_readable () {

  394. #########################################################################
  395. #                                    #
  396. # Convert a value in to human readable size and populate a variable    #
  397. # with the result.                            #
  398. #                                    #
  399. # Call using:                                #
  400. #    human_readable $value \'variable name\' [ places of precision]    #
  401. #                                    #
  402. #########################################################################

  403.     ## value=$1
  404.     ## variable=$2
  405.     scale=$3

  406.     if [ $1 -ge 1073741824 ] ; then
  407.         if [ -z $3 ] ; then
  408.             scale=2
  409.         fi
  410.         divide $1 1073741824 \"$2\" $scale
  411.         unit=\"G\"
  412.     elif [ $1 -ge 1048576 ] ; then
  413.         if [ -z $3 ] ; then
  414.             scale=0
  415.         fi
  416.         divide $1 1048576 \"$2\" $scale
  417.      unit=\"M\"
  418.     elif [ $1 -ge 1024 ] ; then
  419.         if [ -z $3 ] ; then
  420.             scale=0
  421.         fi
  422.         divide $1 1024 \"$2\" $scale
  423.      unit=\"K\"
  424.     else
  425.         export \"$2\"=$1
  426.      unit=\"bytes\"
  427.     fi
  428.     # let \"$2\"=$HR
  429. }

  430. human_readable_time () {

  431. ########################################################################
  432. #                                 #
  433. #    Function to produce human readable time #
  434. #                                 #
  435. ########################################################################

  436.     usage=\"$0 seconds \'variable\'\"
  437.     if [ -z $1 ] || [ -z $2 ] ; then
  438.         cecho $usage red
  439.         exit 1
  440.     fi
  441.     days=$(echo \"scale=0 ; $1 / 86400\" | bc -l)
  442.     remainder=$(echo \"scale=0 ; $1 % 86400\" | bc -l)
  443.     hours=$(echo \"scale=0 ; $remainder / 3600\" | bc -l)
  444.     remainder=$(echo \"scale=0 ; $remainder % 3600\" | bc -l)
  445.     minutes=$(echo \"scale=0 ; $remainder / 60\" | bc -l)
  446.     seconds=$(echo \"scale=0 ; $remainder % 60\" | bc -l)
  447.     export $2=\"$days days $hours hrs $minutes min $seconds sec\"
  448. }

  449. check_mysql_version () {

  450. ## -- Print Version Info -- ##

  451.     mysql_variable \\\'version\\\' mysql_version
  452.     mysql_variable \\\'version_compile_machine\\\' mysql_version_compile_machine
  453.     
  454. if [ \"$major_version\" = \'3.23\' ] || [ \"$major_version\" = \'4.0\' ] ; then
  455.     cecho \"MySQL Version $mysql_version $mysql_version_compile_machine is EOL please upgrade to MySQL 4.1 or later\" boldred
  456. else
  457.     cecho \"MySQL Version $mysql_version $mysql_version_compile_machine\"
  458. fi


  459. }

  460. post_uptime_warning () {

  461. #########################################################################
  462. #                                    #
  463. # Present a reminder that mysql must run for a couple of days to    #
  464. # build up good numbers in server status variables before these tuning    #
  465. # suggestions should be used.                        #
  466. #                                    #
  467. #########################################################################

  468.     mysql_status \\\'Uptime\\\' uptime
  469.     mysql_status \\\'Threads_connected\\\' threads
  470.     queries_per_sec=$(($questions/$uptime))
  471.     human_readable_time $uptime uptimeHR

  472.     cecho \"Uptime = $uptimeHR\"
  473.     cecho \"Avg. qps = $queries_per_sec\"
  474.     cecho \"Total Questions = $questions\"
  475.     cecho \"Threads Connected = $threads\"
  476.     echo

  477.     if [ $uptime -gt 172800 ] ; then
  478.         cecho \"Server has been running for over 48hrs.\"
  479.         cecho \"It should be safe to follow these recommendations\"
  480.     else
  481.         cechon \"Warning: \" boldred
  482.         cecho \"Server has not been running for at least 48hrs.\" boldred
  483.         cecho \"It may not be safe to use these recommendations\" boldred

  484.     fi
  485.     echo \"\"
  486.     cecho \"To find out more information on how each of these\" red
  487.     cecho \"runtime variables effects performance visit:\" red
  488.     if [ \"$major_version\" = \'3.23\' ] || [ \"$major_version\" = \'4.0\' ] || [ \"$major_version\" = \'4.1\' ] ; then
  489.     cecho \"http://dev.mysql.com/doc/refman/4.1/en/server-system-variables.html\" boldblue
  490.     elif [ \"$major_version\" = \'5.0\' ] || [ \"$major_version\" = \'5.1\' ] ; then
  491.     cecho \"http://dev.mysql.com/doc/refman/$major_version/en/server-system-variables.html\" boldblue
  492.     else
  493.     cecho \"UNSUPPORTED MYSQL VERSION\" boldred
  494.     exit 1
  495.     fi
  496.     cecho \"Visit \" boldblue
  497.     cecho \"for info about MySQL\'s Enterprise Monitoring and Advisory Service\" boldblue
  498. }

  499. check_slow_queries () {

  500. ## -- Slow Queries -- ##

  501.     cecho \"SLOW QUERIES\" boldblue

  502.     mysql_status \\\'Slow_queries\\\' slow_queries
  503.     mysql_variable \\\'long_query_time\\\' long_query_time
  504.     mysql_variable \\\'log%queries\\\' log_slow_queries
  505.     
  506.     prefered_query_time=5
  507.     if [ -e /etc/my.cnf ] ; then
  508.         if [ -z $log_slow_queries ] ; then
  509.             log_slow_queries=$(grep log-slow-queries /etc/my.cnf)
  510.         fi
  511.     fi

  512.     if [ \"$log_slow_queries\" = \'ON\' ] ; then
  513.         cecho \"The slow query log is enabled.\"
  514.     elif [ \"$log_slow_queries\" = \'OFF\' ] ; then
  515.         cechon \"The slow query log is \"
  516.         cechon \"NOT\" boldred
  517.         cecho \" enabled.\"
  518.     elif [ -z $log_slow_queries ] ; then
  519.         cechon \"The slow query log is \"
  520.         cechon \"NOT\" boldred
  521.         cecho \" enabled.\"
  522.     else
  523.         cecho \"Error: $log_slow_queries\" boldred
  524.     fi
  525.     cecho \"Current long_query_time = $long_query_time sec.\"
  526.     cechon \"You have \"
  527.     cechon \"$slow_queries\" boldred
  528.     cechon \" out of \"
  529.     cechon \"$questions\" boldred
  530.     cecho \" that take longer than $long_query_time sec. to complete\"
  531.     
  532.     float2int long_query_time long_query_timeInt

  533.     if [ $long_query_timeInt -gt $prefered_query_time ] ; then
  534.                 cecho \"Your long_query_time may be too high, I typically set this under $prefered_query_time sec.\" red
  535.     else
  536.         cecho \"Your long_query_time seems to be fine\" green
  537.     fi

  538. }

  539. check_binary_log () {

  540. ## -- Binary Log -- ##

  541.     cecho \"BINARY UPDATE LOG\" boldblue

  542.     mysql_variable \\\'log_bin\\\' log_bin
  543.     mysql_variable \\\'max_binlog_size\\\' max_binlog_size
  544.     mysql_variable \\\'expire_logs_days\\\' expire_logs_days
  545.     mysql_variable \\\'sync_binlog\\\' sync_binlog
  546.     # mysql_variable \\\'max_binlog_cache_size\\\' max_binlog_cache_size

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

  570. check_used_connections () {

  571. ## -- Used Connections -- ##

  572.     mysql_variable \\\'max_connections\\\' max_connections
  573.     mysql_status \\\'Max_used_connections\\\' max_used_connections
  574.     mysql_status \\\'Threads_connected\\\' threads_connected

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

  576.     cecho \"MAX CONNECTIONS\" boldblue
  577.     cecho \"Current max_connections = $max_connections\"
  578.     cecho \"Current threads_connected = $threads_connected\"
  579.     cecho \"Historic max_used_connections = $max_used_connections\"
  580.     cechon \"The number of used connections is \"
  581.     if [ $connections_ratio -ge 85 ] ; then
  582.         txt_color=red
  583.         error=1
  584.     elif [ $connections_ratio -le 10 ] ; then
  585.         txt_color=red
  586.         error=2
  587.     else
  588.         txt_color=green
  589.         error=0
  590.     fi
  591.     # cechon \"$max_used_connections \" $txt_color
  592.     # cechon \"which is \"
  593.     cechon \"$connections_ratio% \" $txt_color
  594.     cecho \"of the configured maximum.\"

  595.     if [ $error -eq 1 ] ; then
  596.         cecho \"You should raise max_connections\" $txt_color
  597.     elif [ $error -eq 2 ] ; then
  598.         cecho \"You are using less than 10% of your configured max_connections.\" $txt_color
  599.         cecho \"Lowering max_connections could help to avoid an over-allocation of memory\" $txt_color
  600.         cecho \"See \\\"MEMORY USAGE\\\" section to make sure you are not over-allocating\" $txt_color
  601.     else
  602.         cecho \"Your max_connections variable seems to be fine.\" $txt_color
  603.     fi
  604.     unset txt_color
  605. }

  606. check_threads() {

  607. ## -- Worker Threads -- ##

  608.     cecho \"WORKER THREADS\" boldblue

  609.     mysql_status \\\'Threads_created\\\' threads_created1
  610.     sleep 1
  611.     mysql_status \\\'Threads_created\\\' threads_created2

  612.     mysql_status \\\'Threads_cached\\\' threads_cached
  613.     mysql_status \\\'Uptime\\\' uptime
  614.     mysql_variable \\\'thread_cache_size\\\' thread_cache_size

  615.     historic_threads_per_sec=$(($threads_created1/$uptime))
  616.     current_threads_per_sec=$(($threads_created2-$threads_created1))

  617.     cecho \"Current thread_cache_size = $thread_cache_size\"
  618.     cecho \"Current threads_cached = $threads_cached\"
  619.     cecho \"Current threads_per_sec = $current_threads_per_sec\"
  620.     cecho \"Historic threads_per_sec = $historic_threads_per_sec\"

  621.     if [ $historic_threads_per_sec -ge 2 ] && [ $threads_cached -le 1 ] ; then
  622.         cecho \"Threads created per/sec are overrunning threads cached\" red
  623.         cecho \"You should raise thread_cache_size\" red
  624.     elif [ $current_threads_per_sec -ge 2 ] ; then
  625.         cecho \"Threads created per/sec are overrunning threads cached\" red
  626.         cecho \"You should raise thread_cache_size\" red
  627.     else
  628.         cecho \"Your thread_cache_size is fine\" green
  629.     fi
  630. }

  631. check_key_buffer_size () {

  632. ## -- Key buffer Size -- ##

  633.     cecho \"KEY BUFFER\" boldblue

  634.     mysql_status \\\'Key_read_requests\\\' key_read_requests
  635.     mysql_status \\\'Key_reads\\\' key_reads
  636.     mysql_status \\\'Key_blocks_used\\\' key_blocks_used
  637.     mysql_status \\\'Key_blocks_unused\\\' key_blocks_unused
  638.     mysql_variable \\\'key_cache_block_size\\\' key_cache_block_size
  639.     mysql_variable \\\'key_buffer_size\\\' key_buffer_size
  640.         mysql_variable \\\'datadir\\\' datadir
  641.         mysql_variable \\\'version_compile_machine\\\' mysql_version_compile_machine
  642.     myisam_indexes=$($mysql -Bse \"/*!50000 SELECT IFNULL(SUM(INDEX_LENGTH),0) from information_schema.TABLES where ENGINE=\'MyISAM\' */\")

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

  646.         if [ $key_reads -eq 0 ] ; then
  647.                 cecho \"No key reads?!\" boldred
  648.                 cecho \"Seriously look into using some indexes\" red
  649.                 key_cache_miss_rate=0
  650.                 key_buffer_free=$(echo \"$key_blocks_unused * $key_cache_block_size / $key_buffer_size * 100\" | bc -l )
  651.                 key_buffer_freeRND=$(echo \"scale=0; $key_buffer_free / 1\" | bc -l)
  652.         else
  653.                 key_cache_miss_rate=$(($key_read_requests/$key_reads))
  654.                 if [ ! -z $key_blocks_unused ] ; then
  655.             key_buffer_free=$(echo \"$key_blocks_unused * $key_cache_block_size / $key_buffer_size * 100\" | bc -l )
  656.                     key_buffer_freeRND=$(echo \"scale=0; $key_buffer_free / 1\" | bc -l)
  657.                 else
  658.                         key_buffer_free=\'Unknown\'
  659.                         key_buffer_freeRND=75
  660.                 fi
  661.         fi

  662.     human_readable $myisam_indexes myisam_indexesHR
  663.     cecho \"Current MyISAM index space = $myisam_indexesHR $unit\"

  664.     human_readable $key_buffer_size key_buffer_sizeHR
  665.     cecho \"Current key_buffer_size = $key_buffer_sizeHR $unit\"
  666.     cecho \"Key cache miss rate is 1 : $key_cache_miss_rate\"
  667.     cecho \"Key buffer free ratio = $key_buffer_freeRND %\"

  668.     if [ \"$major_version\" = \'5.1\' ] && [ $mysql_version_num -lt \'5123\' ] ; then
  669.         if [ $key_buffer_size -ge 4294967296 ] && ( echo \"x86_64 ppc64 ia64 sparc64 i686\" | grep -q $mysql_version_compile_machine ) ; then
  670.             cecho \"Using key_buffer_size > 4GB will cause instability in versions prior to 5.1.23 \" boldred
  671.             cecho \"See Bug#5731, Bug#29419, Bug#29446\" boldred
  672.         fi
  673.     fi
  674.     if [ \"$major_version\" = \'5.0\' ] && [ $mysql_version_num -lt \'5052\' ] ; then
  675.         if [ $key_buffer_size -ge 4294967296 ] && ( echo \"x86_64 ppc64 ia64 sparc64 i686\" | grep -q $mysql_version_compile_machine ) ; then
  676.             cecho \"Using key_buffer_size > 4GB will cause instability in versions prior to 5.0.52 \" boldred
  677.             cecho \"See Bug#5731, Bug#29419, Bug#29446\" boldred
  678.         fi
  679.     fi
  680.     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
  681.         cecho \"Using key_buffer_size > 4GB will cause instability in versions prior to 5.0.52 \" boldred
  682.         cecho \"Reduce key_buffer_size to a safe value\" boldred
  683.         cecho \"See Bug#5731, Bug#29419, Bug#29446\" boldred
  684.     fi

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

  700. check_query_cache () {

  701. ## -- Query Cache -- ##

  702.     cecho \"QUERY CACHE\" boldblue

  703.     mysql_variable \\\'version\\\' mysql_version
  704.     mysql_variable \\\'query_cache_size\\\' query_cache_size
  705.     mysql_variable \\\'query_cache_limit\\\' query_cache_limit
  706.     mysql_variable \\\'query_cache_min_res_unit\\\' query_cache_min_res_unit
  707.     mysql_status \\\'Qcache_free_memory\\\' qcache_free_memory
  708.     mysql_status \\\'Qcache_total_blocks\\\' qcache_total_blocks
  709.     mysql_status \\\'Qcache_free_blocks\\\' qcache_free_blocks
  710.     mysql_status \\\'Qcache_lowmem_prunes\\\' qcache_lowmem_prunes

  711.     if [ -z $query_cache_size ] ; then
  712.         cecho \"You are using MySQL $mysql_version, no query cache is supported.\" red
  713.         cecho \"I recommend an upgrade to MySQL 4.1 or better\" red
  714.     elif [ $query_cache_size -eq 0 ] ; then
  715.         cecho \"Query cache is supported but not enabled\" red
  716.         cecho \"Perhaps you should set the query_cache_size\" red
  717.     else
  718.         qcache_used_memory=$(($query_cache_size-$qcache_free_memory))
  719.         qcache_mem_fill_ratio=$(echo \"scale=2; $qcache_used_memory * 100 / $query_cache_size\" | bc -l)
  720.         qcache_mem_fill_ratioHR=$(echo \"scale=0; $qcache_mem_fill_ratio / 1\" | bc -l)

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

  744.         if [ $qcache_mem_fill_ratioHR -le 25 ] ; then
  745.              cecho \"Your query_cache_size seems to be too high.\" red
  746.      cecho \"Perhaps you can use these resources elsewhere\" red
  747.         fi
  748.         if [ $qcache_lowmem_prunes -ge 50 ] && [ $qcache_mem_fill_ratioHR -ge 80 ]; then
  749.             cechon \"However, \"
  750.             cechon \"$qcache_lowmem_prunes \" boldred
  751.             cecho \"queries have been removed from the query cache due to lack of memory\"
  752.             cecho \"Perhaps you should raise query_cache_size\" boldred
  753.         fi
  754.         cecho \"MySQL won\'t cache query results that are larger than query_cache_limit in size\" yellow
  755.     fi

  756. }

  757. check_sort_operations () {

  758. ## -- Sort Operations -- ##

  759.     cecho \"SORT OPERATIONS\" boldblue

  760.     mysql_status \\\'Sort_merge_passes\\\' sort_merge_passes
  761.     mysql_status \\\'Sort_scan\\\' sort_scan
  762.     mysql_status \\\'Sort_range\\\' sort_range
  763.     mysql_variable \\\'sort_buffer%\\\' sort_buffer_size
  764.     mysql_variable \\\'read_rnd_buffer_size\\\' read_rnd_buffer_size

  765.     total_sorts=$(($sort_scan+$sort_range))
  766.     if [ -z $read_rnd_buffer_size ] ; then
  767.         mysql_variable \\\'record_buffer\\\' read_rnd_buffer_size
  768.     fi

  769.     ## Correct for rounding error in mysqld where 512K != 524288 ##
  770.     sort_buffer_size=$(($sort_buffer_size+8))
  771.     read_rnd_buffer_size=$(($read_rnd_buffer_size+8))

  772.     human_readable $sort_buffer_size sort_buffer_sizeHR
  773.     cecho \"Current sort_buffer_size = $sort_buffer_sizeHR $unit\"

  774.     human_readable $read_rnd_buffer_size read_rnd_buffer_sizeHR
  775.     cechon \"Current \"
  776.     if [ \"$major_version\" = \'3.23\' ] ; then
  777.         cechon \"record_rnd_buffer \"
  778.     else
  779.         cechon \"read_rnd_buffer_size \"
  780.     fi
  781.     cecho \"= $read_rnd_buffer_sizeHR $unit\"

  782.     if [ $total_sorts -eq 0 ] ; then
  783.         cecho \"No sort operations have been performed\"
  784.         passes_per_sort=0
  785.     fi
  786.     if [ $sort_merge_passes -ne 0 ] ; then
  787.         passes_per_sort=$(($sort_merge_passes/$total_sorts))
  788.     else
  789.         passes_per_sort=0
  790.     fi

  791.     if [ $passes_per_sort -ge 2 ] ; then
  792.         cechon \"On average \"
  793.         cechon \"$passes_per_sort \" boldred
  794.         cecho \"sort merge passes are made per sort operation\"
  795.         cecho \"You should raise your sort_buffer_size\"
  796.         cechon \"You should also raise your \"
  797.         if [ \"$major_version\" = \'3.23\' ] ; then
  798.             cecho \"record_rnd_buffer_size\"
  799.         else
  800.             cecho \"read_rnd_buffer_size\"
  801.         fi
  802.     else
  803.         cecho \"Sort buffer seems to be fine\" green
  804.     fi
  805. }

  806. check_join_operations () {

  807. ## -- Joins -- ##

  808.     cecho \"JOINS\" boldblue

  809.     mysql_status \\\'Select_full_join\\\' select_full_join
  810.     mysql_status \\\'Select_range_check\\\' select_range_check
  811.     mysql_variable \\\'join_buffer%\\\' join_buffer_size
  812.     
  813.     ## Some 4K is dropped from join_buffer_size adding it back to make sane ##
  814.     ## handling of human-readable conversion ##

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

  816.     human_readable $join_buffer_size join_buffer_sizeHR 2

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

  819.     if [ $select_range_check -eq 0 ] && [ $select_full_join -eq 0 ] ; then
  820.         cecho \"Your joins seem to be using indexes properly\" green
  821.     fi
  822.     if [ $select_full_join -gt 0 ] ; then
  823.         print_error=\'true\'
  824.         raise_buffer=\'true\'
  825.     fi
  826.     if [ $select_range_check -gt 0 ] ; then
  827.         cecho \"You have had $select_range_check joins without keys that check for key usage after each row\" red
  828.         print_error=\'true\'
  829.         raise_buffer=\'true\'
  830.     fi

  831.     ## For Debuging ##
  832.     # print_error=\'true\'
  833.     if [ $join_buffer_size -ge 4194304 ] ; then
  834.         cecho \"join_buffer_size >= 4 M\" boldred
  835.         cecho \"This is not advised\" boldred
  836.         raise_buffer=
  837.     fi

  838.     if [ $print_error ] ; then
  839.         if [ \"$major_version\" = \'3.23\' ] || [ \"$major_version\" = \'4.0\' ] ; then
  840.             cecho \"You should enable \\\"log-long-format\\\" \"
  841.         elif [ \"$major_version\" = \'4.1\' ] || [ \"$major_version\" = \'5.0\' ] || [ \"$major_version\" = \'5.1\' ] ; then
  842.             cecho \"You should enable \\\"log-queries-not-using-indexes\\\"\"
  843.         fi
  844.         cecho \"Then look for non indexed joins in the slow query log.\"
  845.         if [ $raise_buffer ] ; then
  846.         cecho \"If you are unable to optimize your queries you may want to increase your\"
  847.         cecho \"join_buffer_size to accommodate larger joins in one pass.\"
  848.         printf \"\\n\"
  849.         cecho \"Note! This script will still suggest raising the join_buffer_size when\" boldred
  850.         cecho \"ANY joins not using indexes are found.\" boldred
  851.         fi
  852.     fi

  853.     # XXX Add better tests for join_buffer_size XXX #
  854. }

  855. check_tmp_tables () {

  856. ## -- Temp Tables -- ##

  857.     cecho \"TEMP TABLES\" boldblue

  858.     mysql_status \\\'Created_tmp_tables\\\' created_tmp_tables
  859.     mysql_status \\\'Created_tmp_disk_tables\\\' created_tmp_disk_tables
  860.     mysql_variable \\\'tmp_table_size\\\' tmp_table_size
  861.     mysql_variable \\\'max_heap_table_size\\\' max_heap_table_size


  862.     if [ $created_tmp_tables -eq 0 ] ; then
  863.         tmp_disk_tables=0
  864.     else
  865.         tmp_disk_tables=$((created_tmp_disk_tables*100/(created_tmp_tables+created_tmp_disk_tables)))
  866.     fi
  867.     human_readable $max_heap_table_size max_heap_table_sizeHR
  868.     cecho \"Current max_heap_table_size = $max_heap_table_sizeHR $unit\"

  869.     human_readable $tmp_table_size tmp_table_sizeHR
  870.     cecho \"Current tmp_table_size = $tmp_table_sizeHR $unit\"

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

  885. check_open_files () {

  886. ## -- Open Files Limit -- ##
  887.     cecho \"OPEN FILES LIMIT\" boldblue

  888.     mysql_variable \\\'open_files_limit\\\' open_files_limit
  889.     mysql_status \\\'Open_files\\\' open_files
  890.     
  891.     if [ -z $open_files_limit ] || [ $open_files_limit -eq 0 ] ; then
  892.         open_files_limit=$(ulimit -n)
  893.         cant_override=1
  894.     else
  895.         cant_override=0
  896.     fi
  897.     cecho \"Current open_files_limit = $open_files_limit files\"
  898.     
  899.     open_files_ratio=$(($open_files*100/$open_files_limit))

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

  916.     

  917. }

  918. check_table_cache () {

  919. ## -- Table Cache -- ##

  920.     cecho \"TABLE CACHE\" boldblue

  921.     mysql_variable \\\'datadir\\\' datadir
  922.     mysql_variable \\\'table_cache\\\' table_cache

  923.     ## /* MySQL +5.1 version of table_cache */ ##
  924.     mysql_variable \\\'table_open_cache\\\' table_open_cache
  925.     mysql_variable \\\'table_definition_cache\\\' table_definition_cache

  926.     mysql_status \\\'Open_tables\\\' open_tables
  927.     mysql_status \\\'Opened_tables\\\' opened_tables
  928.     mysql_status \\\'Open_table_definitions\\\' open_table_definitions
  929.  
  930.     table_count=$($mysql -Bse \"/*!50000 SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE=\'BASE TABLE\' */\")

  931.     if [ -z \"$table_count\" ] ; then
  932.         if [ \"$UID\" != \"$socket_owner\" ] && [ \"$UID\" != \"0\" ] ; then
  933.             cecho \"You are not \'$socket_owner\' or \'root\'\" red
  934.             cecho \"I am unable to determine the table_count!\" red
  935.         else
  936.             table_count=$(find $datadir 2>&1 | grep -c .frm$)
  937.         fi
  938.     fi
  939.     if [ $table_open_cache ] ; then
  940.         table_cache=$table_open_cache
  941.     fi

  942.     if [ $opened_tables -ne 0 ] && [ $table_cache -ne 0 ] ; then
  943.         table_cache_hit_rate=$(($open_tables*100/$opened_tables))
  944.         table_cache_fill=$(($open_tables*100/$table_cache))
  945.     elif [ $opened_tables -eq 0 ] && [ $table_cache -ne 0 ] ; then
  946.         table_cache_hit_rate=100
  947.         table_cache_fill=$(($open_tables*100/$table_cache))
  948.     else
  949.         cecho \"ERROR no table_cache ?!\" boldred
  950.         exit 1
  951.     fi
  952.     if [ $table_cache ] && [ ! $table_open_cache ] ; then
  953.         cecho \"Current table_cache value = $table_cache tables\"
  954.     fi
  955.     if [ $table_open_cache ] ; then
  956.         cecho \"Current table_open_cache = $table_open_cache tables\"
  957.         cecho \"Current table_definition_cache = $table_definition_cache tables\"
  958.     fi
  959.     if [ $table_count ] ; then
  960.     cecho \"You have a total of $table_count tables\"
  961.     fi

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

  989. check_table_locking () {

  990. ## -- Table Locking -- ##

  991.     cecho \"TABLE LOCKING\" boldblue

  992.     mysql_status \\\'Table_locks_waited\\\' table_locks_waited
  993.     mysql_status \\\'Table_locks_immediate\\\' table_locks_immediate
  994.     mysql_variable \\\'concurrent_insert\\\' concurrent_insert
  995.     mysql_variable \\\'low_priority_updates\\\' low_priority_updates
  996.         if [ \"$concurrent_insert\" = \'ON\' ]; then
  997.                 concurrent_insert=1
  998.         elif [ \"$concurrent_insert\" = \'OFF\' ]; then
  999.                 concurrent_insert=0
  1000.         fi

  1001.     cechon \"Current Lock Wait ratio = \"
  1002.     if [ $table_locks_waited -gt 0 ]; then
  1003.         immediate_locks_miss_rate=$(($table_locks_immediate/$table_locks_waited))
  1004.         cecho \"1 : $immediate_locks_miss_rate\" red
  1005.     else
  1006.         immediate_locks_miss_rate=99999 # perfect
  1007.         cecho \"0 : $questions\"
  1008.     fi
  1009.     if [ $immediate_locks_miss_rate -lt 5000 ] ; then
  1010.         cecho \"You may benefit from selective use of InnoDB.\"
  1011.         if [ \"$low_priority_updates\" = \'OFF\' ] ; then
  1012.         cecho \"If you have long running SELECT\'s against MyISAM tables and perform\"
  1013.         cecho \"frequent updates consider setting \'low_priority_updates=1\'\"
  1014.         fi
  1015.         if [ $concurrent_insert -le 1 ] && [ \"$major_version\" = \'5.0\' -o \"$major_version\" = \'5.1\' ] ; then
  1016.         cecho \"If you have a high concurrency of inserts on Dynamic row-length tables\"
  1017.         cecho \"consider setting \'concurrent_insert=2\'.\"
  1018.         fi
  1019.     else
  1020.         cecho \"Your table locking seems to be fine\" green
  1021.     fi
  1022. }

  1023. check_table_scans () {

  1024. ## -- Table Scans -- ##

  1025.     cecho \"TABLE SCANS\" boldblue

  1026.     mysql_status \\\'Com_select\\\' com_select
  1027.     mysql_status \\\'Handler_read_rnd_next\\\' read_rnd_next
  1028.     mysql_variable \\\'read_buffer_size\\\' read_buffer_size

  1029.     if [ -z $read_buffer_size ] ; then
  1030.         mysql_variable \\\'record_buffer\\\' read_buffer_size
  1031.     fi

  1032.      human_readable $read_buffer_size read_buffer_sizeHR
  1033.     cecho \"Current read_buffer_size = $read_buffer_sizeHR $unit\"
  1034.     
  1035.     if [ $com_select -gt 0 ] ; then
  1036.         full_table_scans=$(($read_rnd_next/$com_select))
  1037.         cecho \"Current table scan ratio = $full_table_scans : 1\"
  1038.         if [ $full_table_scans -ge 4000 ] && [ $read_buffer_size -le 2097152 ] ; then
  1039.             cecho \"You have a high ratio of sequential access requests to SELECTs\" red
  1040.             cechon \"You may benefit from raising \" red
  1041.             if [ \"$major_version\" = \'3.23\' ] ; then
  1042.                 cechon \"record_buffer \" red
  1043.             else
  1044.                 cechon \"read_buffer_size \" red
  1045.             fi
  1046.             cecho \"and/or improving your use of indexes.\" red
  1047.         elif [ $read_buffer_size -gt 8388608 ] ; then
  1048.             cechon \"read_buffer_size is over 8 MB \" red
  1049.             cecho \"there is probably no need for such a large read_buffer\" red
  1050.         
  1051.         else
  1052.             cecho \"read_buffer_size seems to be fine\" green
  1053.         fi
  1054.     else
  1055.         cecho \"read_buffer_size seems to be fine\" green
  1056.     fi
  1057. }


  1058. check_innodb_status () {

  1059. ## -- InnoDB -- ##

  1060.     mysql_variable \\\'have_innodb\\\' have_innodb

  1061.     if [ \"$have_innodb\" = \"YES\" ] ; then
  1062.         mysql_variable \\\'innodb_buffer_pool_size\\\' innodb_buffer_pool_size
  1063.         mysql_variable \\\'innodb_additional_mem_pool_size\\\' innodb_additional_mem_pool_size
  1064.         mysql_variable \\\'innodb_fast_shutdown\\\' innodb_fast_shutdown
  1065.         mysql_variable \\\'innodb_flush_log_at_trx_commit\\\' innodb_flush_log_at_trx_commit
  1066.         mysql_variable \\\'innodb_locks_unsafe_for_binlog\\\' innodb_locks_unsafe_for_binlog
  1067.         mysql_variable \\\'innodb_log_buffer_size\\\' innodb_log_buffer_size
  1068.         mysql_variable \\\'innodb_log_file_size\\\' innodb_log_file_size
  1069.         mysql_variable \\\'innodb_log_files_in_group\\\' innodb_log_files_in_group
  1070.         mysql_variable \\\'innodb_safe_binlog\\\' innodb_safe_binlog
  1071.         mysql_variable \\\'innodb_thread_concurrency\\\' innodb_thread_concurrency

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

  1077.         mysql_status \\\'Innodb_buffer_pool_pages_data\\\' innodb_buffer_pool_pages_data
  1078.         mysql_status \\\'Innodb_buffer_pool_pages_misc\\\' innodb_buffer_pool_pages_misc
  1079.         mysql_status \\\'Innodb_buffer_pool_pages_free\\\' innodb_buffer_pool_pages_free
  1080.         mysql_status \\\'Innodb_buffer_pool_pages_total\\\' innodb_buffer_pool_pages_total

  1081.         mysql_status \\\'Innodb_buffer_pool_read_ahead_seq\\\' innodb_buffer_pool_read_ahead_seq
  1082.         mysql_status \\\'Innodb_buffer_pool_read_requests\\\' innodb_buffer_pool_read_requests

  1083.         mysql_status \\\'Innodb_os_log_pending_fsyncs\\\' innodb_os_log_pending_fsyncs
  1084.         mysql_status \\\'Innodb_os_log_pending_writes\\\'    innodb_os_log_pending_writes
  1085.         mysql_status \\\'Innodb_log_waits\\\' innodb_log_waits

  1086.         mysql_status \\\'Innodb_row_lock_time\\\' innodb_row_lock_time
  1087.         mysql_status \\\'Innodb_row_lock_waits\\\' innodb_row_lock_waits

  1088.         human_readable $innodb_indexes innodb_indexesHR
  1089.         cecho \"Current InnoDB index space = $innodb_indexesHR $unit\"
  1090.         human_readable $innodb_data innodb_dataHR
  1091.         cecho \"Current InnoDB data space = $innodb_dataHR $unit\"
  1092.         percent_innodb_buffer_pool_free=$(($innodb_buffer_pool_pages_free*100/$innodb_buffer_pool_pages_total))
  1093.         cecho \"Current InnoDB buffer pool free = \"$percent_innodb_buffer_pool_free\" %\"

  1094.         else
  1095.         cecho \"Cannot parse InnoDB stats prior to 5.0.x\" red
  1096.         $mysql -s -e \"SHOW /*!50000 ENGINE */ INNODB STATUS\\G\"
  1097.         fi

  1098.         human_readable $innodb_buffer_pool_size innodb_buffer_pool_sizeHR
  1099.         cecho \"Current innodb_buffer_pool_size = $innodb_buffer_pool_sizeHR $unit\"
  1100.         cecho \"Depending on how much space your innodb indexes take up it may be safe\"
  1101.         cecho \"to increase this value to up to 2 / 3 of total system memory\"
  1102.     else
  1103.         cecho \"No InnoDB Support Enabled!\" boldred
  1104.     fi
  1105. }

  1106. total_memory_used () {

  1107. ## -- Total Memory Usage -- ##
  1108.     cecho \"MEMORY USAGE\" boldblue

  1109.     mysql_variable \\\'read_buffer_size\\\' read_buffer_size
  1110.     mysql_variable \\\'read_rnd_buffer_size\\\' read_rnd_buffer_size
  1111.     mysql_variable \\\'sort_buffer_size\\\' sort_buffer_size
  1112.     mysql_variable \\\'thread_stack\\\' thread_stack
  1113.     mysql_variable \\\'max_connections\\\' max_connections
  1114.     mysql_variable \\\'join_buffer_size\\\' join_buffer_size
  1115.     mysql_variable \\\'tmp_table_size\\\' tmp_table_size
  1116.     mysql_variable \\\'max_heap_table_size\\\' max_heap_table_size
  1117.     mysql_variable \\\'log_bin\\\' log_bin
  1118.     mysql_status \\\'Max_used_connections\\\' max_used_connections

  1119.     if [ \"$major_version\" = \"3.23\" ] ; then
  1120.         mysql_variable \\\'record_buffer\\\' read_buffer_size
  1121.         mysql_variable \\\'record_rnd_buffer\\\' read_rnd_buffer_size
  1122.         mysql_variable \\\'sort_buffer\\\' sort_buffer_size
  1123.     fi

  1124.     if [ \"$log_bin\" = \"ON\" ] ; then
  1125.         mysql_variable \\\'binlog_cache_size\\\' binlog_cache_size
  1126.     else
  1127.         binlog_cache_size=0
  1128.     fi

  1129.     if [ $max_heap_table_size -le $tmp_table_size ] ; then
  1130.         effective_tmp_table_size=$max_heap_table_size
  1131.     else
  1132.         effective_tmp_table_size=$tmp_table_size
  1133.     fi


  1134.     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)
  1135.     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)

  1136.         mysql_variable \\\'innodb_buffer_pool_size\\\' innodb_buffer_pool_size
  1137.         if [ -z $innodb_buffer_pool_size ] ; then
  1138.         innodb_buffer_pool_size=0
  1139.         fi

  1140.         mysql_variable \\\'innodb_additional_mem_pool_size\\\' innodb_additional_mem_pool_size
  1141.         if [ -z $innodb_additional_mem_pool_size ] ; then
  1142.         innodb_additional_mem_pool_size=0
  1143.         fi

  1144.         mysql_variable \\\'innodb_log_buffer_size\\\' innodb_log_buffer_size
  1145.         if [ -z $innodb_log_buffer_size ] ; then
  1146.         innodb_log_buffer_size=0
  1147.         fi

  1148.         mysql_variable \\\'key_buffer_size\\\' key_buffer_size

  1149.         mysql_variable \\\'query_cache_size\\\' query_cache_size
  1150.         if [ -z $query_cache_size ] ; then
  1151.         query_cache_size=0
  1152.         fi

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


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

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

  1157.     if [ $pct_of_sys_mem -gt 90 ] ; then
  1158.         txt_color=boldred
  1159.         error=1
  1160.     else
  1161.         txt_color=
  1162.         error=0
  1163.     fi    

  1164.     human_readable $max_memory max_memoryHR
  1165.     cecho \"Max Memory Ever Allocated : $max_memoryHR $unit\" $txt_color
  1166.     human_readable $per_thread_buffers per_thread_buffersHR
  1167.     cecho \"Configured Max Per-thread Buffers : $per_thread_buffersHR $unit\" $txt_color
  1168.     human_readable $global_buffers global_buffersHR
  1169.     cecho \"Configured Max Global Buffers : $global_buffersHR $unit\" $txt_color
  1170.     human_readable $total_memory total_memoryHR
  1171.     cecho \"Configured Max Memory Limit : $total_memoryHR $unit\" $txt_color
  1172. #    human_readable $effective_tmp_table_size effective_tmp_table_sizeHR
  1173. #    cecho \"Plus $effective_tmp_table_sizeHR $unit per temporary table created\"
  1174.     human_readable $physical_memory physical_memoryHR
  1175.     cecho \"Physical Memory : $physical_memoryHR $unit\" $txt_color
  1176.     if [ $error -eq 1 ] ; then
  1177.         printf \"\\n\"
  1178.         cecho \"nMax memory limit exceeds 90% of physical memory\" $txt_color
  1179.     else
  1180.         cecho \"Max memory limit seem to be within acceptable norms\" green
  1181.     fi
  1182.     unset txt_color
  1183. }

  1184. ## Required Functions ##

  1185. login_validation () {
  1186.     check_for_socket         # determine the socket location -- 1st login
  1187.     check_for_plesk_passwords    # determine the login method -- 2nd login
  1188.     check_mysql_login        # determine if mysql is accepting login -- 3rd login
  1189.     export major_version=$($mysql -Bse \"SELECT SUBSTRING_INDEX(VERSION(), \'.\', +2)\")
  1190.     export mysql_version_num=$($mysql -Bse \"SELECT LEFT(REPLACE(SUBSTRING_INDEX(VERSION(), \'-\', +1), \'.\', \'\'),4)\" )
  1191. }

  1192. shared_info () {
  1193.     export major_version=$($mysql -Bse \"SELECT SUBSTRING_INDEX(VERSION(), \'.\', +2)\")
  1194.     export mysql_version_num=$($mysql -Bse \"SELECT LEFT(REPLACE(SUBSTRING_INDEX(VERSION(), \'-\', +1), \'.\', \'\'),4)\" )
  1195.     mysql_status \\\'Questions\\\' questions
  1196. #    socket_owner=$(find -L $socket -printf \'%u\\n\')
  1197.     socket_owner=$(ls -nH $socket | awk \'{ print $3 }\')
  1198. }
  1199.     

  1200. get_system_info () {

  1201.     export OS=$(uname)
  1202.     
  1203.     # Get information for various UNIXes
  1204.     if [ \"$OS\" = \'Darwin\' ]; then
  1205.     ps_socket=$(netstat -ln | awk \'/mysql(d)?\\.sock/ { print $9 }\' | head -1)
  1206.     found_socks=$(netstat -ln | awk \'/mysql(d)?\\.sock/ { print $9 }\')
  1207.         export physical_memory=$(sysctl -n hw.memsize)
  1208.     export duflags=\'\'
  1209.     elif [ \"$OS\" = \'FreeBSD\' ] || [ \"$OS\" = \'OpenBSD\' ]; then
  1210.     ## On FreeBSD must be root to locate sockets.
  1211.     ps_socket=$(netstat -ln | awk \'/mysql(d)?\\.sock/ { print $9 }\' | head -1)
  1212.     found_socks=$(netstat -ln | awk \'/mysql(d)?\\.sock/ { print $9 }\')
  1213.         export physical_memory=$(sysctl -n hw.realmem)
  1214.     export duflags=\'\'
  1215.     elif [ \"$OS\" = \'Linux\' ] ; then
  1216.     ## Includes SWAP
  1217.         ## export physical_memory=$(free -b | grep -v buffers | awk \'{ s += $2 } END { printf(\"%.0f\\n\", s ) }\')
  1218.     ps_socket=$(netstat -ln | awk \'/mysql(d)?\\.sock/ { print $9 }\' | head -1)
  1219.     found_socks=$(netstat -ln | awk \'/mysql(d)?\\.sock/ { print $9 }\')
  1220.     export physical_memory=$(awk \'/^MemTotal/ { printf(\"%.0f\", $2*1024 ) }\' < /proc/meminfo)
  1221.     export duflags=\'-b\'
  1222.     elif [ \"$OS\" = \'SunOS\' ] ; then
  1223.     ps_socket=$(netstat -a | awk \'/mysql(d)?.sock/ { print $5 }\' | head -1)
  1224.     found_socks=$(netstat -a | awk \'/mysql(d)?.sock/ { print $5 }\')
  1225.     export physical_memory=$(prtconf | awk \'/^Memory\\ size:/ { print $3*1048576 }\')
  1226.     fi
  1227. }


  1228. ## Optional Components Groups ##

  1229. banner_info () {
  1230.     shared_info
  1231.     print_banner        ; echo
  1232.     check_mysql_version    ; echo
  1233.     post_uptime_warning    ; echo
  1234. }

  1235. misc () {
  1236.     shared_info
  1237.     check_slow_queries    ; echo
  1238.     check_binary_log    ; echo
  1239.     check_threads        ; echo
  1240.     check_used_connections    ; echo
  1241.     check_innodb_status    ; echo
  1242. }

  1243. memory () {
  1244.     shared_info
  1245.     total_memory_used    ; echo
  1246.     check_key_buffer_size    ; echo
  1247.     check_query_cache    ; echo
  1248.     check_sort_operations    ; echo
  1249.     check_join_operations    ; echo
  1250. }

  1251. file () {
  1252.     shared_info
  1253.     check_open_files    ; echo
  1254.     check_table_cache    ; echo
  1255.     check_tmp_tables    ; echo
  1256.     check_table_scans    ; echo
  1257.     check_table_locking    ; echo
  1258. }

  1259. all () {
  1260.     banner_info
  1261.     misc
  1262.     memory
  1263.     file
  1264. }

  1265. prompt () {
  1266.     prompted=\'true\'
  1267.     read -p \"Username [anonymous] : \" user
  1268.     read -rp \"Password [] : \" pass
  1269.     cecho \" \"
  1270.     read -p \"Socket [ /var/lib/mysql/mysql.sock ] : \" socket
  1271.     if [ -z $socket ] ; then
  1272.         export socket=\'/var/lib/mysql/mysql.sock\'
  1273.     fi

  1274.     if [ -z $pass ] ; then
  1275.     export mysql=\"mysql -S $socket -u$user\"
  1276.     export mysqladmin=\"mysqladmin -S $socket -u$user\"
  1277.     else
  1278.         export mysql=\"mysql -S $socket -u$user -p$pass\"
  1279.         export mysqladmin=\"mysqladmin -S $socket -u$user -p$pass\"
  1280.     fi

  1281.     check_for_socket
  1282.     check_mysql_login

  1283.     if [ $? = 1 ] ; then
  1284.         exit 1
  1285.     fi
  1286.     read -p \"Mode to test - banner, file, misc, mem, innodb, [all] : \" REPLY
  1287.     if [ -z $REPLY ] ; then
  1288.         REPLY=\'all\'
  1289.     fi
  1290.     case $REPLY in
  1291.      banner | BANNER | header | HEADER | head | HEAD)
  1292.         banner_info
  1293.         ;;
  1294.         misc | MISC | miscelaneous )
  1295.         misc
  1296.         ;;
  1297.             mem | memory | MEM | MEMORY )
  1298.         memory
  1299.         ;;
  1300.         file | FILE | disk | DISK )
  1301.         file
  1302.         ;;
  1303.         innodb | INNODB )
  1304.         innodb
  1305.         ;;
  1306.         all | ALL )
  1307.         cecho \" \"
  1308.         all
  1309.         ;;
  1310.         * )
  1311.         cecho \"Invalid Mode! Valid options are \'banner\', \'misc\', \'memory\', \'file\', \'innodb\' or \'all\'\" boldred
  1312.         exit 1
  1313.         ;;
  1314.     esac
  1315. }

  1316. ## Address environmental differences ##
  1317. get_system_info
  1318. # echo $ps_socket

  1319. if [ -z \"$1\" ] ; then
  1320.     login_validation
  1321.     mode=\'ALL\'
  1322. elif [ \"$1\" = \"prompt\" ] || [ \"$1\" = \"PROMPT\" ] ; then
  1323.     mode=$1
  1324. elif [ \"$1\" != \"prompt\" ] || [ \"$1\" != \"PROMPT\" ] ; then
  1325.     login_validation
  1326.     mode=$1
  1327. fi

  1328. case $mode in
  1329.     all | ALL )
  1330.     cecho \" \"
  1331.     all
  1332.     ;;
  1333.     mem | memory | MEM | MEMORY )
  1334.     cecho \" \"
  1335.     memory
  1336.     ;;
  1337.     file | FILE | disk | DISK )
  1338.     cecho \" \"
  1339.     file
  1340.     ;;
  1341.     banner | BANNER | header | HEADER | head | HEAD )
  1342.     banner_info
  1343.     ;;
  1344.     misc | MISC | miscelaneous )
  1345.     cecho \" \"
  1346.     misc
  1347.     ;;
  1348.     innodb | INNODB )
  1349.     banner_info
  1350.     check_innodb_status ; echo
  1351.     ;;
  1352.     prompt | PROMPT )
  1353.     prompt
  1354.     ;;
  1355.     *)
  1356.     cecho \"usage: $0 [ all | banner | file | innodb | memory | misc | prompt ]\" boldred
  1357.     exit 1
  1358.     ;;
  1359. esac

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29734436/viewspace-1280690/,如需轉載,請註明出處,否則將追究法律責任。

相關文章