[opencms-dev] Script: Optimize all Tables (mysql) via bash/shell Script

ls contact at living-structures.de
Fri Jul 24 11:08:49 CEST 2009


I found this little script to optimize all mysql tables via bash/shell,
but i didn't know how to include username and pass (authentication).

Can someone please extend/complete the mysql-statement ?

regards,
Andrew

___________________________optimize_all_table.h
#!/bin/sh

DBNAME=$2

printUsage() {
  echo "Usage: $0"
  echo " --optimize <tablename>"
  return
}


doAllTables() {
  TABLENAMES=`mysql -D $DBNAME -e "SHOW TABLES\G;"|grep 'Tables_in_'|sed 
-n 's/.*Tables_in_.*: \([_0-9A-Za-z]*\).*/\1/p'`

  for TABLENAME in $TABLENAMES
  do
    mysql -D $DBNAME -e "OPTIMIZE TABLE $TABLENAME;"
  done
}

if [ $# -eq 0 ] ; then
  printUsage
  exit 1
fi

case $1 in
  --optimize) doAllTables;;
  --help) printUsage; exit 1;;
  *) printUsage; exit 1;;
esac

______________________EOF




More information about the opencms-dev mailing list