Fix errors in case of multiple mysql installations.
This commit is contained in:
@@ -257,6 +257,23 @@ if $NON_INTERACTIVE_MODE && [[ -z "$DATABASE_NAME" ]]; then
|
||||
fi
|
||||
|
||||
|
||||
echononl " Get MySQL command.."
|
||||
mysql_command="$(which mysql)"
|
||||
if [[ $? -eq 0 ]]; then
|
||||
echo_ok
|
||||
else
|
||||
|
||||
if [[ -x "/usr/local/mysql/bin/mysql" ]]; then
|
||||
mysql_command="/usr/local/mysql/bin/mysql"
|
||||
echo_ok
|
||||
else
|
||||
echo_failed
|
||||
fatal "$(cat $tmp_log_file)"
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
|
||||
if [[ -n "$DATABASE_NAME" ]] ; then
|
||||
if [[ -z "$DATABASE_USER" || -z "$DATABASE_PASSWD" ]] ; then
|
||||
read_file=""
|
||||
@@ -358,7 +375,15 @@ if ! $NON_INTERACTIVE_MODE ; then
|
||||
|
||||
mysql_version="${_val_arr[0]}"
|
||||
mysql_credential_args="${_val_arr[1]}"
|
||||
mysql_dist_string="$(mysql $mysql_credential_args -N -s -e "SELECT VERSION()" 2> /dev/null)"
|
||||
mysql_dist_string="$(${mysql_command} $mysql_credential_args -N -s -e "SELECT VERSION()" 2> ${tmp_log_file})"
|
||||
if [[ $? -ne 0 ]] ; then
|
||||
if [[ "$(cat $tmp_log_file)" =~ "unknown variable 'login-path" ]] ; then
|
||||
if [[ -x "/usr/local/mysql/bin/mysql" ]] ; then
|
||||
mysql_dist_string="$(/usr/local/mysql/bin/mysql $mysql_credential_args -N -s -e "SELECT VERSION()" 2> /dev/null)"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ "$mysql_dist_string" =~ MariaDB ]]; then
|
||||
mysql_dist="MariaDB $mysql_version"
|
||||
else
|
||||
@@ -428,10 +453,28 @@ if $MYSQL_CREDENTIALS_GIVEN ; then
|
||||
echo -e "\033[32m--\033[m"
|
||||
echo ""
|
||||
echononl " Get MySQL Version"
|
||||
_version="$(mysql $MYSQL_CREDENTIAL_ARGS -N -s -e "SELECT VERSION()" 2> $tmp_log_file)"
|
||||
_version="$(${mysql_command} $MYSQL_CREDENTIAL_ARGS -N -s -e "SELECT VERSION()" 2> $tmp_log_file)"
|
||||
if [[ $? -ne 0 ]] ; then
|
||||
echo_failed
|
||||
fatal "$(cat $tmp_log_file)"
|
||||
if [[ "$(cat $tmp_log_file)" =~ "unknown variable 'login-path" ]] ; then
|
||||
if [[ -x "/usr/local/mysql/bin/mysql" ]] ; then
|
||||
mysql_command="/usr/local/mysql/bin/mysql"
|
||||
else
|
||||
echo_failed
|
||||
fatal "$(cat $tmp_log_file)"
|
||||
fi
|
||||
|
||||
_version="$(${mysql_command} $MYSQL_CREDENTIAL_ARGS -N -s -e "SELECT VERSION()" 2> $tmp_log_file)"
|
||||
if [[ $? -ne 0 ]] ; then
|
||||
echo_failed
|
||||
fatal "$(cat $tmp_log_file)"
|
||||
else
|
||||
echo_ok
|
||||
fi
|
||||
else
|
||||
echo_failed
|
||||
fatal "$(cat $tmp_log_file)"
|
||||
fi
|
||||
|
||||
else
|
||||
echo_ok
|
||||
fi
|
||||
@@ -481,7 +524,7 @@ else
|
||||
parameter manually."
|
||||
fi
|
||||
else
|
||||
if $(mysql --login-path=local -e ";" > /dev/null 2>&1) ; then
|
||||
if $(${mysql_command} --login-path=local -e ";" > /dev/null 2>&1) ; then
|
||||
MYSQL_CREDENTIAL_ARGS="--login-path=local"
|
||||
elif [[ -f "/usr/local/mysql/sys-maint.cnf" ]] ; then
|
||||
MYSQL_CREDENTIAL_ARGS="--defaults-file=/usr/local/mysql/sys-maint.cnf"
|
||||
@@ -508,6 +551,8 @@ if ! $QUIET_MODE ; then
|
||||
echo " MySQL Version................: ${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_LEVEL}"
|
||||
echo " MySQL Credentials............: $MYSQL_CREDENTIAL_ARGS"
|
||||
echo ""
|
||||
echo " MySQL commnd.................: ${mysql_command}"
|
||||
echo ""
|
||||
echo -e " Drop Database user...........: \033[33m$DATABASE_USER\033[m"
|
||||
echo ""
|
||||
echo ""
|
||||
@@ -536,7 +581,7 @@ fi
|
||||
# - Check if User already exists
|
||||
# -
|
||||
echononl " Check if user '$DATABASE_USER' exists .."
|
||||
if [[ "$(mysql $MYSQL_CREDENTIAL_ARGS -se "SELECT EXISTS(SELECT 1 FROM mysql.user WHERE user = '${DATABASE_USER}')")" = "1" ]]; then
|
||||
if [[ "$(${mysql_command} $MYSQL_CREDENTIAL_ARGS -se "SELECT EXISTS(SELECT 1 FROM mysql.user WHERE user = '${DATABASE_USER}')")" = "1" ]]; then
|
||||
user_exists=true
|
||||
else
|
||||
user_exists=false
|
||||
@@ -548,7 +593,7 @@ echo_ok
|
||||
# - Test given user is associated with a database
|
||||
# -
|
||||
echononl " Check if db user '$DATABASE_USER' is associated with a database"
|
||||
_count_user="$(mysql $MYSQL_CREDENTIAL_ARGS mysql -N -s -e \
|
||||
_count_user="$(${mysql_command} $MYSQL_CREDENTIAL_ARGS mysql -N -s -e \
|
||||
"SELECT count(User) FROM db WHERE User = '$DATABASE_USER'" 2> $tmp_log_file)"
|
||||
if [[ -z "$_count_user" ]]; then
|
||||
echo_failed
|
||||
@@ -565,7 +610,7 @@ fi
|
||||
|
||||
echononl " Delete username '$DATABASE_USER' from table mysql.db"
|
||||
if [[ $_count_user -gt 0 ]]; then
|
||||
mysql $MYSQL_CREDENTIAL_ARGS mysql -N -s -e \
|
||||
${mysql_command} $MYSQL_CREDENTIAL_ARGS mysql -N -s -e \
|
||||
"DELETE FROM db WHERE User = '$DATABASE_USER'" > $tmp_log_file 2>&1
|
||||
if [[ $? -ne 0 ]] ; then
|
||||
echo_failed
|
||||
@@ -579,7 +624,7 @@ fi
|
||||
|
||||
echononl " Delete username '$DATABASE_USER' from table mysql.user"
|
||||
if $user_exists ; then
|
||||
mysql $MYSQL_CREDENTIAL_ARGS mysql -N -s -e \
|
||||
${mysql_command} $MYSQL_CREDENTIAL_ARGS mysql -N -s -e \
|
||||
"DELETE FROM user WHERE User = '$DATABASE_USER'" > $tmp_log_file 2>&1
|
||||
if [[ $? -ne 0 ]] ; then
|
||||
echo_failed
|
||||
@@ -594,7 +639,7 @@ else
|
||||
fi
|
||||
|
||||
echononl " Flush Privileges.."
|
||||
mysql $MYSQL_CREDENTIAL_ARGS -N -s -e "FLUSH PRIVILEGES" > $tmp_log_file 2>&1
|
||||
${mysql_command} $MYSQL_CREDENTIAL_ARGS -N -s -e "FLUSH PRIVILEGES" > $tmp_log_file 2>&1
|
||||
if [[ $? -ne 0 ]] ; then
|
||||
echo_failed
|
||||
error "$(cat $tmp_log_file)"
|
||||
|
||||
Reference in New Issue
Block a user