mysql/flush_host_cache.sh
2017-02-21 02:31:30 +01:00

50 lines
1.2 KiB
Bash
Executable File

#!/usr/bin/env bash
#LOGGING=true
LOGGING=false
mysqladmin=`realpath $(which mysqladmin) 2>/dev/null`
if [ -z "$mysqladmin" ]; then
if [ -x "/usr/local/mysql/bin/mysqladmin" ]; then
mysql=/usr/local/mysql/bin/mysqladmin
else
echo
echo -e "\t[ Error ]: \"mysqladmin\" not found !!!"
echo
exit
fi
fi
## - Since Version 5.6, that method is considered as insecure.
## - To avoid giving the password on command line, we use an
## - encrypted option file
## -
## - Create (encrypted) option file:
## - $ mysql_config_editor set --login-path=local --socket=/var/run/mysqld/mysqld.sock --user=backup --password
## - $ Password:
## -
## - Use of option file:
## - $ mysql --login-path=local ...
## -
mysql_credential_args="--login-path=local"
#mysql_user='sys-maint'
#mysql_password='9A7NUgaJST1XiEUU'
if $LOGGING ;then
echo -e "\n[ `date` ] Going to flush host cache.."
fi
if [ -n "$mysql_credential_args" ] ; then
$mysqladmin $mysql_credential_args flush-hosts
else
$mysqladmin -u$mysql_user -p$mysql_password flush-hosts
fi
[[ $? -gt 0 ]] && echo -e "\t[ Error ]: Flushing host cache failed !!"
if $LOGGING ;then
echo -e "\n[ `date` ] End flushing host cache"
fi
exit 0