Fix errors in case of multiple mysql installations.

This commit is contained in:
2024-01-17 01:40:49 +01:00
parent 62c2f65dbd
commit 845e9cf8ad
14 changed files with 976 additions and 345 deletions

View File

@@ -245,6 +245,22 @@ 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
# -------------
# - Load Settings from configuration file mysql_credetials.conf
@@ -297,7 +313,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> /dev/null)"
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
@@ -357,10 +381,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
@@ -410,7 +452,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"
@@ -436,6 +478,8 @@ if ! $QUIET_MODE ; then
echo " MySQL Distribution...........: $MYSQL_CUR_DISTRIBUTION"
echo " MySQL Version................: ${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_LEVEL}"
echo " MySQL Credentials............: $MYSQL_CREDENTIAL_ARGS"
echo ""
echo " MySQL commnd.................: ${mysql_command}"
echo ""
echo " Database name................: $DATABASE_NAME"
@@ -455,7 +499,7 @@ if ! $NON_INTERACTIVE_MODE ; then
fi
_result="$(mysql $MYSQL_CREDENTIAL_ARGS -N -s -e "SHOW DATABASES LIKE '$DATABASE_NAME'")"
_result="$(${mysql_command} $MYSQL_CREDENTIAL_ARGS -N -s -e "SHOW DATABASES LIKE '$DATABASE_NAME'")"
if [[ -z "$_result" ]]; then
fatal "No database '$DATABASE_NAME' found!"
fi
@@ -469,7 +513,7 @@ if ! $QUIET_MODE ; then
fi
echononl " Get table list from database '$DATABASE_NAME' .."
_TABLES="$(mysql $MYSQL_CREDENTIAL_ARGS $DATABASE_NAME -N -s -e "show tables" 2> $tmp_log_file)"
_TABLES="$(${mysql_command} $MYSQL_CREDENTIAL_ARGS $DATABASE_NAME -N -s -e "show tables" 2> $tmp_log_file)"
if [[ $? -ne 0 ]] ; then
echo_failed
fatal "$(cat $tmp_log_file)"
@@ -486,7 +530,7 @@ echononl " Drop tables form database '$DATABASE_NAME' .."
_failed=false
> $tmp_log_file
for _table in $_TABLES ; do
mysql $MYSQL_CREDENTIAL_ARGS $DATABASE_NAME -N -s -e "DROP TABLE \`$_table\`" >> $tmp_log_file 2>&1
${mysql_command} $MYSQL_CREDENTIAL_ARGS $DATABASE_NAME -N -s -e "DROP TABLE \`$_table\`" >> $tmp_log_file 2>&1
if [[ $? -ne 0 ]] ; then
_failed=true
_tables_not_yet_deleted+=("$_table")
@@ -509,7 +553,7 @@ if $_failed ; then
_failed_again=false
: > $tmp_log_file
for _table in "${_tables_not_yet_deleted[@]}" ; do
mysql $MYSQL_CREDENTIAL_ARGS $DATABASE_NAME -N -s -e "DROP TABLE \`$_table\`" >> $tmp_log_file 2>&1
${mysql_command} $MYSQL_CREDENTIAL_ARGS $DATABASE_NAME -N -s -e "DROP TABLE \`$_table\`" >> $tmp_log_file 2>&1
if [[ $? -ne 0 ]] ; then
_failed_again=true
_tables_not_deleted+=("$_table")