optimize_mysql_tables.sh: if a database is given at the command line, only check tables of this database.
This commit is contained in:
parent
6c2e2bee12
commit
a842cf5906
@ -16,6 +16,42 @@ DEFAULT_MYSQL_CREDENTIAL_ARGS="--login-path=local"
|
||||
# --- Some functions
|
||||
# -------------
|
||||
|
||||
usage() {
|
||||
|
||||
[[ -n "$1" ]] && error "$1"
|
||||
|
||||
[[ $terminal ]] && echo -e "
|
||||
\033[1mUsage:\033[m
|
||||
|
||||
$(basename $0) [DB-Name]
|
||||
|
||||
\033[1mDescription\033[m
|
||||
|
||||
Script checks (and reorganizes) all tables of all databases by executing MySQL
|
||||
command 'OPTIMIZE TABLE'.
|
||||
|
||||
If a database is given at the command line, only tables of that database
|
||||
will be checked.
|
||||
|
||||
If a check on a table fails, MySQL command 'REPAIR TABLE' will be executed on
|
||||
that table.
|
||||
|
||||
\033[1mOptions\033[m
|
||||
|
||||
No Options available
|
||||
|
||||
\033[1mFiles\033[m
|
||||
|
||||
$conf_file: Configuration file
|
||||
|
||||
|
||||
"
|
||||
|
||||
clean_up 1
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
clean_up() {
|
||||
|
||||
@ -108,14 +144,18 @@ echo_skipped() {
|
||||
fi
|
||||
}
|
||||
|
||||
trim() {
|
||||
local var="$*"
|
||||
var="${var#"${var%%[![:space:]]*}"}" # remove leading whitespace characters
|
||||
var="${var%"${var##*[![:space:]]}"}" # remove trailing whitespace characters
|
||||
echo -n "$var"
|
||||
}
|
||||
|
||||
|
||||
|
||||
trap clean_up SIGHUP SIGINT SIGTERM
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# - Is this script running on terminal ?
|
||||
# -
|
||||
if [[ -t 1 ]] ; then
|
||||
@ -135,11 +175,23 @@ if [ -z "$mysql" ]; then
|
||||
fi
|
||||
|
||||
|
||||
# - Print help?
|
||||
# -
|
||||
if [[ "$(trim $*)" = "-h" ]] || [[ "$(trim $*)" = "--help" ]] ; then
|
||||
usage
|
||||
fi
|
||||
|
||||
|
||||
# -------------
|
||||
# - Load Settings from configuration file
|
||||
# -------------
|
||||
|
||||
if [[ -n "$1 " ]] ; then
|
||||
DATABASES="$1"
|
||||
else
|
||||
DATABASES=""
|
||||
fi
|
||||
|
||||
if $terminal ; then
|
||||
echo ""
|
||||
fi
|
||||
@ -183,7 +235,9 @@ for _val in ${mysql_credential_args_arr[@]} ; do
|
||||
echo -e "[ \033[37m\033[1mMySQL $mysql_version\033[m ]: optimize (and repair) tables of databases at host '$(hostname -f)'."
|
||||
fi
|
||||
|
||||
DATABASES=`$mysql $mysql_credential_args -N -s -e "show databases"`
|
||||
if [[ -z "$DATABASES" ]] ; then
|
||||
DATABASES="$($mysql $mysql_credential_args -N -s -e "show databases")"
|
||||
fi
|
||||
|
||||
length_table_name=0
|
||||
for db in $DATABASES ; do
|
||||
|
Loading…
Reference in New Issue
Block a user