mysql/flush_query_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
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
## - 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 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