second run: determin 'MYSQL_CREDENTIAL_ARGS' if not given.
This commit is contained in:
parent
ea8fc078c2
commit
9ddc792d23
@ -6,6 +6,58 @@ conf_file="${working_dir}/conf/mysql_credetials.conf"
|
||||
#LOGGING=true
|
||||
LOGGING=false
|
||||
|
||||
|
||||
# -------------
|
||||
# --- Some functions
|
||||
# -------------
|
||||
|
||||
fatal(){
|
||||
echo ""
|
||||
if $terminal ; then
|
||||
if [[ -n "$*" ]] ; then
|
||||
echo -e " [ \033[31m\033[1mFatal\033[m ]: $*"
|
||||
echo ""
|
||||
echo -e " \033[31m\033[1mScript will be interrupted.\033[m\033[m"
|
||||
else
|
||||
echo -e " \033[31m\033[1mFatal error\033[m: \033[1mScript will be interrupted.\033[m"
|
||||
fi
|
||||
else
|
||||
if [[ -n "$*" ]] ; then
|
||||
echo " [ Fatal ]: $*"
|
||||
echo ""
|
||||
echo " Script was terminated.."
|
||||
else
|
||||
echo " Fatal error: Script was terminated.."
|
||||
fi
|
||||
fi
|
||||
echo ""
|
||||
clean_up 1
|
||||
}
|
||||
|
||||
detect_mysql_version () {
|
||||
|
||||
_MYSQLD_VERSION="$(mysqld -V 2>/dev/null)"
|
||||
|
||||
if [[ -z "$_MYSQLD_VERSION" ]]; then
|
||||
fatal "No installed MySQL server or distribution found!"
|
||||
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
|
||||
|
||||
MYSQL_VERSION="$(echo $_MYSQLD_VERSION | grep -o -E "[0-9]+\.[0-9]+\.[0-9]+(-[0-9]+)?" | head -n 1)"
|
||||
MYSQL_MAJOR_VERSION="$(echo $MYSQL_VERSION | cut -d '.' -f1)"
|
||||
MYSQL_MINOR_VERSION="$(echo $MYSQL_VERSION | cut -d '.' -f2)"
|
||||
MYSQL_PATCH_LEVEL="$(echo $MYSQL_VERSION | cut -d '.' -f3)"
|
||||
MYSQL_MAIN_VERSION="$(echo $MYSQL_VERSION | cut -d '.' -f1,2)"
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
mysqladmin=`realpath $(which mysqladmin) 2>/dev/null`
|
||||
if [ -z "$mysqladmin" ]; then
|
||||
if [ -x "/usr/local/mysql/bin/mysqladmin" ]; then
|
||||
@ -19,6 +71,16 @@ if [ -z "$mysqladmin" ]; then
|
||||
fi
|
||||
|
||||
|
||||
# - Is this script running on terminal ?
|
||||
# -
|
||||
if [[ -t 1 ]] ; then
|
||||
terminal=true
|
||||
else
|
||||
terminal=false
|
||||
fi
|
||||
|
||||
|
||||
|
||||
#---------------------------------------
|
||||
#-----------------------------
|
||||
# Read Configurations from $conf_file
|
||||
@ -29,18 +91,51 @@ if [[ -f "$conf_file" ]]; then
|
||||
source "$conf_file"
|
||||
fi
|
||||
|
||||
[[ -z "$mysql_credential_args" ]] && mysql_credential_args="--defaults-file=/usr/local/mysql/sys-maint.cnf"
|
||||
#[[ -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 host cache.."
|
||||
fi
|
||||
|
||||
if [ -n "$mysql_credential_args" ] ; then
|
||||
$mysqladmin $mysql_credential_args flush-hosts
|
||||
if [[ -z "$mysql_credential_args" ]]; then
|
||||
|
||||
detect_mysql_version
|
||||
|
||||
MAJOR_VERSION="$MYSQL_MAJOR_VERSION"
|
||||
MINOR_VERSION="$MYSQL_MINOR_VERSION"
|
||||
PATCH_LEVEL="$MYSQL_PATCH_LEVEL"
|
||||
|
||||
if [[ "$MYSQL_CUR_DISTRIBUTION" = "MariaDB" ]] && ([[ $MAJOR_VERSION -gt 10 ]] \
|
||||
|| ( [[ $MAJOR_VERSION -eq 10 ]] && [[ $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
|
||||
$mysqladmin -u$mysql_user -p$mysql_password flush-hosts
|
||||
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
|
||||
|
||||
|
||||
# Flush host cache
|
||||
#
|
||||
$mysqladmin $mysql_credential_args flush-hosts
|
||||
|
||||
[[ $? -gt 0 ]] && echo -e "\t[ Error ]: Flushing host cache failed !!"
|
||||
|
||||
|
@ -64,18 +64,47 @@ if [[ -f "$conf_file" ]]; then
|
||||
source "$conf_file"
|
||||
fi
|
||||
|
||||
[[ -z "$mysql_credential_args" ]] && mysql_credential_args="--defaults-file=/usr/local/mysql/sys-maint.cnf"
|
||||
#[[ -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
|
||||
|
||||
if [ -n "$mysql_credential_args" ] ; then
|
||||
|
||||
# Flush Query Cache
|
||||
#
|
||||
$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 !!"
|
||||
|
||||
|
@ -159,6 +159,28 @@ trim() {
|
||||
echo -n "$var"
|
||||
}
|
||||
|
||||
detect_mysql_version () {
|
||||
|
||||
_MYSQLD_VERSION="$(mysqld -V 2>/dev/null)"
|
||||
|
||||
if [[ -z "$_MYSQLD_VERSION" ]]; then
|
||||
fatal "No installed MySQL server or distribution found!"
|
||||
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
|
||||
|
||||
MYSQL_VERSION="$(echo $_MYSQLD_VERSION | grep -o -E "[0-9]+\.[0-9]+\.[0-9]+(-[0-9]+)?" | head -n 1)"
|
||||
MYSQL_MAJOR_VERSION="$(echo $MYSQL_VERSION | cut -d '.' -f1)"
|
||||
MYSQL_MINOR_VERSION="$(echo $MYSQL_VERSION | cut -d '.' -f2)"
|
||||
MYSQL_PATCH_LEVEL="$(echo $MYSQL_VERSION | cut -d '.' -f3)"
|
||||
MYSQL_MAIN_VERSION="$(echo $MYSQL_VERSION | cut -d '.' -f1,2)"
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
trap clean_up SIGHUP SIGINT SIGTERM
|
||||
@ -238,12 +260,46 @@ else
|
||||
fi
|
||||
|
||||
|
||||
[[ -z "$mysql_credential_args" ]] && mysql_credential_args="$DEFAULT_MYSQL_CREDENTIAL_ARGS"
|
||||
#[[ -z "$mysql_credential_args" ]] && mysql_credential_args="$DEFAULT_MYSQL_CREDENTIAL_ARGS"
|
||||
|
||||
if [[ -z "$mysql_credential_args" ]]; then
|
||||
|
||||
detect_mysql_version
|
||||
|
||||
MAJOR_VERSION="$MYSQL_MAJOR_VERSION"
|
||||
MINOR_VERSION="$MYSQL_MINOR_VERSION"
|
||||
PATCH_LEVEL="$MYSQL_PATCH_LEVEL"
|
||||
|
||||
if [[ "$MYSQL_CUR_DISTRIBUTION" = "MariaDB" ]] && ([[ $MAJOR_VERSION -gt 10 ]] \
|
||||
|| ( [[ $MAJOR_VERSION -eq 10 ]] && [[ $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
|
||||
|
||||
[[ -z "$log_file" ]] && log_file="$DEFAULT_LOG_FILE"
|
||||
|
||||
if [[ ${#mysql_credential_args_arr[@]} -eq 0 ]]; then
|
||||
[[ -z "$mysql_credential_args" ]] && mysql_credential_args="$DEFAULT_MYSQL_CREDENTIAL_ARGS"
|
||||
mysql_credential_args_arr="default:$mysql_credential_args"
|
||||
mysql_credential_args_arr[0]="default:$mysql_credential_args"
|
||||
fi
|
||||
|
||||
declare -i length_table_name
|
||||
|
@ -159,6 +159,29 @@ trim() {
|
||||
echo -n "$var"
|
||||
}
|
||||
|
||||
detect_mysql_version () {
|
||||
|
||||
_MYSQLD_VERSION="$(mysqld -V 2>/dev/null)"
|
||||
|
||||
if [[ -z "$_MYSQLD_VERSION" ]]; then
|
||||
fatal "No installed MySQL server or distribution found!"
|
||||
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
|
||||
|
||||
MYSQL_VERSION="$(echo $_MYSQLD_VERSION | grep -o -E "[0-9]+\.[0-9]+\.[0-9]+(-[0-9]+)?" | head -n 1)"
|
||||
MYSQL_MAJOR_VERSION="$(echo $MYSQL_VERSION | cut -d '.' -f1)"
|
||||
MYSQL_MINOR_VERSION="$(echo $MYSQL_VERSION | cut -d '.' -f2)"
|
||||
MYSQL_PATCH_LEVEL="$(echo $MYSQL_VERSION | cut -d '.' -f3)"
|
||||
MYSQL_MAIN_VERSION="$(echo $MYSQL_VERSION | cut -d '.' -f1,2)"
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
trap clean_up SIGHUP SIGINT SIGTERM
|
||||
@ -238,7 +261,42 @@ else
|
||||
fi
|
||||
|
||||
|
||||
[[ -z "$mysql_credential_args" ]] && mysql_credential_args="$DEFAULT_MYSQL_CREDENTIAL_ARGS"
|
||||
#[[ -z "$mysql_credential_args" ]] && mysql_credential_args="$DEFAULT_MYSQL_CREDENTIAL_ARGS"
|
||||
|
||||
if [[ -z "$mysql_credential_args" ]]; then
|
||||
|
||||
detect_mysql_version
|
||||
|
||||
MAJOR_VERSION="$MYSQL_MAJOR_VERSION"
|
||||
MINOR_VERSION="$MYSQL_MINOR_VERSION"
|
||||
PATCH_LEVEL="$MYSQL_PATCH_LEVEL"
|
||||
|
||||
if [[ "$MYSQL_CUR_DISTRIBUTION" = "MariaDB" ]] && ([[ $MAJOR_VERSION -gt 10 ]] \
|
||||
|| ( [[ $MAJOR_VERSION -eq 10 ]] && [[ $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
|
||||
|
||||
[[ -z "$log_file" ]] && log_file="$DEFAULT_LOG_FILE"
|
||||
|
||||
if [[ ${#mysql_credential_args_arr[@]} -eq 0 ]]; then
|
||||
|
@ -161,6 +161,28 @@ trim() {
|
||||
var="${var%"${var##*[![:space:]]}"}" # remove trailing whitespace characters
|
||||
echo -n "$var"
|
||||
}
|
||||
detect_mysql_version () {
|
||||
|
||||
_MYSQLD_VERSION="$(mysqld -V 2>/dev/null)"
|
||||
|
||||
if [[ -z "$_MYSQLD_VERSION" ]]; then
|
||||
fatal "No installed MySQL server or distribution found!"
|
||||
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
|
||||
|
||||
MYSQL_VERSION="$(echo $_MYSQLD_VERSION | grep -o -E "[0-9]+\.[0-9]+\.[0-9]+(-[0-9]+)?" | head -n 1)"
|
||||
MYSQL_MAJOR_VERSION="$(echo $MYSQL_VERSION | cut -d '.' -f1)"
|
||||
MYSQL_MINOR_VERSION="$(echo $MYSQL_VERSION | cut -d '.' -f2)"
|
||||
MYSQL_PATCH_LEVEL="$(echo $MYSQL_VERSION | cut -d '.' -f3)"
|
||||
MYSQL_MAIN_VERSION="$(echo $MYSQL_VERSION | cut -d '.' -f1,2)"
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@ -227,15 +249,50 @@ else
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ -n "$mysql_credential_args" ]]; then
|
||||
MYSQL_CREDENTIAL_ARGS="$mysql_credential_args"
|
||||
else
|
||||
MYSQL_CREDENTIAL_ARGS="$DEFAULT_MYSQL_CREDENTIAL_ARGS"
|
||||
fi
|
||||
|
||||
|
||||
declare -i index_arr=0
|
||||
|
||||
# - Get MySQL Version
|
||||
if [[ -n "$mysql_credential_args" ]]; then
|
||||
MYSQL_CREDENTIAL_ARGS="$mysql_credential_args"
|
||||
MYSQL_CREDENTIALS_GIVEN=true
|
||||
else
|
||||
|
||||
detect_mysql_version
|
||||
|
||||
MAJOR_VERSION="$MYSQL_MAJOR_VERSION"
|
||||
MINOR_VERSION="$MYSQL_MINOR_VERSION"
|
||||
PATCH_LEVEL="$MYSQL_PATCH_LEVEL"
|
||||
|
||||
if [[ "$MYSQL_CUR_DISTRIBUTION" = "MariaDB" ]] && ([[ $MAJOR_VERSION -gt 10 ]] \
|
||||
|| ( [[ $MAJOR_VERSION -eq 10 ]] && [[ $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
|
||||
MYSQL_CREDENTIALS_GIVEN=false
|
||||
fi
|
||||
|
||||
|
||||
# - Get MySQL Version if paralle installations
|
||||
# -
|
||||
if [[ ${#mysql_credential_args_arr[@]} -gt 0 ]] ; then
|
||||
|
||||
@ -301,6 +358,8 @@ if $DATABASE_NAME_NEEDED ; then
|
||||
#done
|
||||
fi
|
||||
|
||||
if $MYSQL_CREDENTIALS_GIVEN ; then
|
||||
|
||||
# - Get MySQL Version
|
||||
# -
|
||||
echo ""
|
||||
@ -337,6 +396,9 @@ echo ""
|
||||
echo -e "\033[32m--\033[m"
|
||||
echo ""
|
||||
|
||||
fi
|
||||
|
||||
|
||||
echo ""
|
||||
echo ""
|
||||
echo -e "\033[32m\033[1m====================\033[m"
|
||||
|
Loading…
Reference in New Issue
Block a user