#!/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 # Get current version # _MYSQLD_VERSION="$(mysqld -V 2>/dev/null)" CURRENT_VERSION="$(echo $_MYSQLD_VERSION | grep -o -E "[0-9]+\.[0-9]+\.[0-9]+(-[0-9]+)?" | head -n 1)" MYSQL_MAIN_VERSION=`echo $CURRENT_VERSION | cut -d '.' -f1,2` MYSQL_MAJOR_VERSION=`echo $CURRENT_VERSION | cut -d '.' -f1` MYSQL_MINOR_VERSION=`echo $CURRENT_VERSION | cut -d '.' -f2` MYSQL_PATCH_LEVEL=`echo $CURRENT_VERSION | cut -d '.' -f3` if [[ -z "$_MYSQLD_VERSION" ]]; then echo "" echo -e "\t[ Error ]: No installed MySQL server or distribution found!" echo "" elif [[ "$_MYSQLD_VERSION" =~ MariaDB ]]; then MYSQL_CUR_DISTRIBUTION="MariaDB" elif [[ "$(basename "$(realpath "/usr/local/mysql")")" =~ percona- ]]; then MYSQL_CUR_DISTRIBUTION="Percona" elif [[ "$(basename "$(realpath "/usr/local/mysql")")" =~ mysql- ]]; then MYSQL_CUR_DISTRIBUTION="MySQL" fi if [[ "$MYSQL_CUR_DISTRIBUTION" = "MySQL" ]]; then if [[ "$MYSQL_MAJOR_VERSION" -gt 8 ]] \ || ( [[ "$MYSQL_MAJOR_VERSION" -eq 8 ]] && [[ "$MYSQL_MINOR_VERSION" -gt 0 ]] ) \ || ( [[ "$MYSQL_MAJOR_VERSION" -eq 8 ]] && [[ "$MYSQL_MINOR_VERSION" -eq 0 ]] \ && [[ $MYSQL_PATCH_LEVEL -ge 3 ]] ); then echo "" echo -e "\t[ Error ]: Query cache is no longer supported since (MySQL 8.0.3)" 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="--defaults-file=/usr/local/mysql/sys-maint.cnf" 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