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

@@ -197,17 +197,23 @@ else
terminal=false
fi
mysql=`which mysql`
echononl " Get MySQL command.."
mysql_command="$(which mysql)"
if [[ $? -eq 0 ]]; then
echo_ok
else
if [ -z "$mysql" ]; then
if [ -x "/usr/local/mysql/bin/mysql" ]; then
mysql=/usr/local/mysql/bin/mysql
if [[ -x "/usr/local/mysql/bin/mysql" ]]; then
mysql_command="/usr/local/mysql/bin/mysql"
echo_ok
else
echo_failed
fatal "No binary 'mysql' found!"
fi
fi
# - Print help?
# -
if [[ "$(trim $*)" = "-h" ]] || [[ "$(trim $*)" = "--help" ]] ; then
@@ -277,7 +283,15 @@ if [[ ${#mysql_credential_args_arr[@]} -gt 0 ]] ; 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
@@ -335,13 +349,31 @@ 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)"
if [[ $? -ne 0 ]] ; then
echo_failed
fatal "$(cat $tmp_log_file)"
else
echo_ok
fi
_version="$(${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_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
IFS='.' read -r -a version_arr <<< "$_version"
declare -i MAJOR_VERSION="${version_arr[0]}"
@@ -388,7 +420,9 @@ else
parameter manually."
fi
else
if [[ -f "/usr/local/mysql/sys-maint.cnf" ]] ; 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"
elif [[ -f "/etc/mysql/debian.cnf" ]] ; then
MYSQL_CREDENTIAL_ARGS="--defaults-file=/etc/mysql/debian.cnf"
@@ -413,6 +447,8 @@ 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 ""
if [[ -n "$DATABASE_NAME" ]]; then
echo " Database name................: $DATABASE_NAME"
else
@@ -440,7 +476,7 @@ declare -i index_i
_all_success=true
DATABASES="$(mysql $MYSQL_CREDENTIAL_ARGS -N -s -e "show databases")"
DATABASES="$(${mysql_command} $MYSQL_CREDENTIAL_ARGS -N -s -e "show databases")"
if [[ -z "$DATABASE_NAME" ]] ; then
@@ -482,7 +518,7 @@ for db in $DATABASES ; do
fi
fi
TABLES="$($mysql $MYSQL_CREDENTIAL_ARGS $db -N -s -e "show tables" 2> $tmp_log_file )"
TABLES="$(${mysql_command} $MYSQL_CREDENTIAL_ARGS $db -N -s -e "show tables" 2> $tmp_log_file )"
if [[ $? -ne 0 ]]; then
_all_success=false
error "Getting tables of database '${db}' failed.\n $(cat "$tmp_log_file")"
@@ -494,7 +530,7 @@ for db in $DATABASES ; do
# - Ommit InnoDB tables
# -
_engine="$($mysql $MYSQL_CREDENTIAL_ARGS -N -s -e "SELECT ENGINE FROM information_schema.TABLES WHERE TABLE_SCHEMA = '$db' AND TABLE_NAME = '$table'")"
_engine="$(${mysql_command} $MYSQL_CREDENTIAL_ARGS -N -s -e "SELECT ENGINE FROM information_schema.TABLES WHERE TABLE_SCHEMA = '$db' AND TABLE_NAME = '$table'")"
if [[ "${_engine,,}" = 'innodb' ]] ; then
echo -e " [$(date)] Ommit table '$table' - The storage engine (InnoDB) doesn't support repair"
continue
@@ -515,7 +551,7 @@ for db in $DATABASES ; do
fi
length_table_name=${#table}
$mysql $MYSQL_CREDENTIAL_ARGS $db -N -s -e "REPAIR TABLE \`$table\`" > $tmp_log_file 2>&1
${mysql_command} $MYSQL_CREDENTIAL_ARGS $db -N -s -e "REPAIR TABLE \`$table\`" > $tmp_log_file 2>&1
if [[ $? -ne 0 ]]; then
@@ -525,7 +561,7 @@ for db in $DATABASES ; do
else
$mysql $MYSQL_CREDENTIAL_ARGS $db -N -s -e "OPTIMIZE TABLE \`$table\`" > $tmp_log_file 2>&1
${mysql_command} $MYSQL_CREDENTIAL_ARGS $db -N -s -e "OPTIMIZE TABLE \`$table\`" > $tmp_log_file 2>&1
if [[ $? -ne 0 ]]; then
error "Reoptimizing table \"${table}\" of database \"$db\" failed.\n$(cat "$tmp_log_file")"