Fix errors in case of multiple mysql installations.
This commit is contained in:
@@ -267,6 +267,21 @@ fi
|
||||
# -
|
||||
clear
|
||||
|
||||
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
|
||||
@@ -319,7 +334,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
|
||||
@@ -441,10 +464,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
|
||||
@@ -494,7 +535,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"
|
||||
@@ -523,6 +564,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 " Database user................: $DATABASE_USER"
|
||||
echo " Database password............: $DATABASE_PASSWD"
|
||||
echo ""
|
||||
@@ -564,7 +607,7 @@ fi
|
||||
# - Check if User already exists
|
||||
# -
|
||||
echononl " Check if user '$DATABASE_USER' already exists for localhost .."
|
||||
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
|
||||
@@ -575,7 +618,7 @@ echo_ok
|
||||
|
||||
echononl " Create database user '$DATABASE_USER' access from locahost"
|
||||
if ! $user_exists ; then
|
||||
mysql $MYSQL_CREDENTIAL_ARGS -N -s -e \
|
||||
${mysql_command} $MYSQL_CREDENTIAL_ARGS -N -s -e \
|
||||
"CREATE USER '$DATABASE_USER'@'localhost' IDENTIFIED BY '$DATABASE_PASSWD'" \
|
||||
> $tmp_log_file 2>&1
|
||||
if [[ $? -ne 0 ]] ; then
|
||||
@@ -588,8 +631,8 @@ else
|
||||
echo_skipped
|
||||
fi
|
||||
|
||||
echononl " Grant permissions to access and use the MySQL server to user '$DATABASE_USER'"
|
||||
mysql $MYSQL_CREDENTIAL_ARGS -N -s -e \
|
||||
echononl " Grant permissions to access and use the ${mysql_command} server to user '$DATABASE_USER'"
|
||||
${mysql_command} $MYSQL_CREDENTIAL_ARGS -N -s -e \
|
||||
"GRANT USAGE ON *.* TO '$DATABASE_USER'@'localhost'" \
|
||||
> $tmp_log_file 2>&1
|
||||
if [[ $? -ne 0 ]] ; then
|
||||
@@ -600,7 +643,7 @@ else
|
||||
fi
|
||||
|
||||
echononl " Grant all privileges to user '$DATABASE_USER' on all database "
|
||||
mysql $MYSQL_CREDENTIAL_ARGS -N -s -e \
|
||||
${mysql_command} $MYSQL_CREDENTIAL_ARGS -N -s -e \
|
||||
"GRANT SELECT, SHOW VIEW, EVENT, LOCK TABLES, RELOAD, REPLICATION CLIENT ON *.* TO '$DATABASE_USER'@'localhost'" \
|
||||
> $tmp_log_file 2>&1
|
||||
if [[ $? -ne 0 ]] ; then
|
||||
@@ -615,7 +658,7 @@ if $ACCESS_FROM_OUTSIDE ; then
|
||||
for _ip in $IP_ADDRESSES ; do
|
||||
|
||||
echononl " Check if user '$DATABASE_USER' already exists for '$_ip' .."
|
||||
_count="$(mysql $MYSQL_CREDENTIAL_ARGS mysql -N -s -e \
|
||||
_count="$(${mysql_command} $MYSQL_CREDENTIAL_ARGS mysql -N -s -e \
|
||||
"SELECT count(User) FROM user WHERE User = '$DATABASE_USER' and Host = '$_ip'" 2> $tmp_log_file)"
|
||||
if [[ -z "$_count" ]]; then
|
||||
echo_failed
|
||||
@@ -624,7 +667,7 @@ if $ACCESS_FROM_OUTSIDE ; then
|
||||
echo_ok
|
||||
|
||||
echononl " Create database user '$DATABASE_USER' for '$_ip'"
|
||||
mysql $MYSQL_CREDENTIAL_ARGS -N -s -e \
|
||||
${mysql_command} $MYSQL_CREDENTIAL_ARGS -N -s -e \
|
||||
"CREATE USER '$DATABASE_USER'@'$_ip' IDENTIFIED BY '$DATABASE_PASSWD'" \
|
||||
> $tmp_log_file 2>&1
|
||||
if [[ $? -ne 0 ]] ; then
|
||||
@@ -639,7 +682,7 @@ if $ACCESS_FROM_OUTSIDE ; then
|
||||
fi
|
||||
|
||||
echononl " Allow access to user '$DATABASE_USER' on all databases from '$_ip'"
|
||||
mysql $MYSQL_CREDENTIAL_ARGS -N -s -e \
|
||||
${mysql_command} $MYSQL_CREDENTIAL_ARGS -N -s -e \
|
||||
"GRANT USAGE ON *.* TO '$DATABASE_USER'@'$_ip'" > $tmp_log_file 2>&1
|
||||
if [[ $? -ne 0 ]] ; then
|
||||
echo_failed
|
||||
@@ -649,7 +692,7 @@ if $ACCESS_FROM_OUTSIDE ; then
|
||||
fi
|
||||
|
||||
echononl " Grant all privileges to user '$DATABASE_USER' on all databases from '$_ip'"
|
||||
mysql $MYSQL_CREDENTIAL_ARGS -N -s -e \
|
||||
${mysql_command} $MYSQL_CREDENTIAL_ARGS -N -s -e \
|
||||
"GRANT SELECT, SHOW VIEW, EVENT, LOCK TABLES, RELOAD, REPLICATION CLIENT ON *.* TO '$DATABASE_USER'@'$_ip'" \
|
||||
> $tmp_log_file 2>&1
|
||||
if [[ $? -ne 0 ]] ; then
|
||||
@@ -666,7 +709,7 @@ 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