mysql/flush_query_cache.sh

52 lines
1.1 KiB
Bash
Executable File

#!/usr/bin/env bash
working_dir="$(dirname $(realpath $0))"
conf_file="${working_dir}/conf/mysql_credetials.conf"
#LOGGING=true
LOGGING=false
mysql=`realpath $(which mysql) 2>/dev/null`
if [ -z "$mysql" ]; then
if [ -x "/usr/local/mysql/bin/mysql" ]; then
mysql=/usr/local/mysql/bin/mysql
else
echo
echo -e "\t[ Error ]: \"mysql\" not found !!!"
echo
exit
fi
fi
#---------------------------------------
#-----------------------------
# Read Configurations from $conf_file
#-----------------------------
#---------------------------------------
if [[ -f "$conf_file" ]]; then
source "$conf_file"
fi
[[ -z "$mysql_credential_args" ]] && mysql_credential_args="--login-path=local"
if $LOGGING ;then
echo -e "\n[ `date` ] Going to flush query cache.."
fi
if [ -n "$mysql_credential_args" ] ; then
$mysql $mysql_credential_args -N -s -e "FLUSH QUERY CACHE"
else
$mysql -u$mysql_user -p$mysql_password -N -s -e "FLUSH QUERY CACHE"
fi
[[ $? -gt 0 ]] && echo -e "\t[ Error ]: Flushing query cache failed !!"
if $LOGGING ;then
echo -e "\n[ `date` ] End flushing query cache"
fi
exit 0