#!/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 [[ -z "$mysql_credential_args" ]]; then if [[ "$MYSQL_CUR_DISTRIBUTION" = "MariaDB" ]] && ([[ $MYSQL_MAJOR_VERSION -gt 10 ]] \ || ( [[ $MYSQL_MAJOR_VERSION -eq 10 ]] && [[ $MYSQL_MINOR_VERSION -gt 3 ]] )) ; then if [[ -S "/tmp/mysql.sock" ]]; then mysql_credential_args="-u root -S /tmp/mysql.sock" elif [[ -S "/var/run/mysqld/mysqld.sock" ]]; then mysql_credential_args="-u root -S /var/run/mysqld/mysqld.sock" else fatal "Parameter 'MYSQL_CREDENTIAL_ARGS' cannot be determined automated. Use configuration file "$conf_file" to set parameter manually." fi else if [[ -f "/usr/local/mysql/sys-maint.cnf" ]] ; then mysql_credential_args="--defaults-file=/usr/local/mysql/sys-maint.cnf" elif [[ -f "/etc/mysql/debian.cnf" ]] ; then mysql_credential_args="--defaults-file=/etc/mysql/debian.cnf" else fatal "Parameter 'MYSQL_CREDENTIAL_ARGS' cannot be determined automated. Use configuration file "$conf_file" to set parameter manually." fi fi fi if $LOGGING ;then echo -e "\n[ `date` ] Going to flush query cache.." fi # Flush Query Cache # $mysql $mysql_credential_args -N -s -e "FLUSH QUERY CACHE" [[ $? -gt 0 ]] && echo -e "\t[ Error ]: Flushing query cache failed !!" if $LOGGING ;then echo -e "\n[ `date` ] End flushing query cache" fi exit 0