Fix errors in case of multiple mysql installations.
This commit is contained in:
@@ -378,6 +378,8 @@ declare -i index_i
|
||||
declare -i index_arr=0
|
||||
while [[ $index_arr -lt ${#mysql_credential_args_arr[@]} ]] ; do
|
||||
|
||||
mysql_command="$mysql"
|
||||
|
||||
_all_success=true
|
||||
|
||||
IFS=':' read -a _val_arr <<< "${mysql_credential_args_arr[$index_arr]}"
|
||||
@@ -385,7 +387,21 @@ while [[ $index_arr -lt ${#mysql_credential_args_arr[@]} ]] ; do
|
||||
mysql_credential_args="${_val_arr[1]}"
|
||||
|
||||
|
||||
DATABASES="$($mysql $mysql_credential_args -N -s -e "show databases")"
|
||||
DATABASES="$(${mysql_command} $mysql_credential_args -N -s -e "show databases" 2> $log_file)"
|
||||
if [[ $? -ne 0 ]] ; then
|
||||
|
||||
if [[ "$(cat $log_file)" =~ "unknown variable 'login-path" ]] ; then
|
||||
if [[ -x "/usr/local/mysql/bin/mysql" ]] ; then
|
||||
mysql_command="/usr/local/mysql/bin/mysql"
|
||||
DATABASES="$(${mysql_command} $mysql_credential_args -N -s -e "show databases" 2> $log_file)"
|
||||
if [[ $? -ne 0 ]] ; then
|
||||
error "$(cat $log_file)"
|
||||
continue
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
found=false
|
||||
if [[ -n "$GIVEN_DATABASE" ]] ; then
|
||||
@@ -498,13 +514,13 @@ while [[ $index_arr -lt ${#mysql_credential_args_arr[@]} ]] ; do
|
||||
|
||||
fi
|
||||
|
||||
TABLES=`$mysql $mysql_credential_args $db -N -s -e "show tables"`
|
||||
TABLES=`${mysql_command} $mysql_credential_args $db -N -s -e "show tables"`
|
||||
|
||||
for table in $TABLES ; 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
|
||||
if $VERBOSE ; then
|
||||
echo -e " [$(date)] Ommit table '$table' - storage engine is InnoDB"
|
||||
@@ -529,7 +545,7 @@ while [[ $index_arr -lt ${#mysql_credential_args_arr[@]} ]] ; do
|
||||
echo -e " [$(date)] Optimize table '$table'" >> $log_file
|
||||
length_table_name=${#table}
|
||||
|
||||
$mysql $mysql_credential_args $db -N -s -e "OPTIMIZE TABLE \`$table\`" > $log_file 2>&1
|
||||
${mysql_command} $mysql_credential_args $db -N -s -e "OPTIMIZE TABLE \`$table\`" > $log_file 2>&1
|
||||
|
||||
|
||||
if [[ $? -ne 0 ]]; then
|
||||
@@ -540,7 +556,7 @@ while [[ $index_arr -lt ${#mysql_credential_args_arr[@]} ]] ; do
|
||||
echo "" >> $log_file
|
||||
echo " [$(date)] Repair table '$table'" >> $log_file
|
||||
|
||||
$mysql $mysql_credential_args $db -N -s -e "REPAIR TABLE \`$table\`" > $log_file 2>&1
|
||||
${mysql_command} $mysql_credential_args $db -N -s -e "REPAIR TABLE \`$table\`" > $log_file 2>&1
|
||||
|
||||
if [[ $? -ne 0 ]]; then
|
||||
|
||||
@@ -554,7 +570,7 @@ while [[ $index_arr -lt ${#mysql_credential_args_arr[@]} ]] ; do
|
||||
else
|
||||
|
||||
echo -e " [$(date)] Optimize table '$table'" >> $log_file
|
||||
$mysql $mysql_credential_args $db -N -s -e "OPTIMIZE TABLE \`$table\`" > $log_file 2>&1
|
||||
${mysql_command} $mysql_credential_args $db -N -s -e "OPTIMIZE TABLE \`$table\`" > $log_file 2>&1
|
||||
|
||||
if [[ $? -ne 0 ]]; then
|
||||
error "Reoptimizing table \"${table}\" of database \"$db\" failed.\n$(cat "$log_file")"
|
||||
|
||||
Reference in New Issue
Block a user