diff --git a/create_database.sh b/create_database.sh index 0670dfc..28f801d 100755 --- a/create_database.sh +++ b/create_database.sh @@ -276,6 +276,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 + + if [[ -n "$DATABASE_NAME" ]] ; then if [[ -z "$DATABASE_USER" || -z "$DATABASE_PASSWD" ]] ; then read_file="" @@ -377,7 +393,14 @@ 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" @@ -578,10 +601,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 @@ -631,7 +672,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" @@ -658,6 +699,9 @@ 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" echo " Database user................: $DATABASE_USER" @@ -703,19 +747,19 @@ fi # - Test if Database already exists # - -_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 [[ "$_result" = "$DATABASE_NAME" ]] ; then fatal "Database '$DATABASE_NAME' already exists" fi echononl " Create database \033[1m$DATABASE_NAME\033[m (full UTF-8 support - ${DATABASE_CHARACTER_SET})" -mysql $MYSQL_CREDENTIAL_ARGS -N -s -e \ +${mysql_command} $MYSQL_CREDENTIAL_ARGS -N -s -e \ "CREATE DATABASE $DATABASE_NAME CHARACTER SET ${DATABASE_CHARACTER_SET} COLLATE ${DATABASE_COLLATION}" > $tmp_log_file 2>&1 if [[ $? -ne 0 ]] ; then echo_failed error "$(cat $tmp_log_file)" echononl " Create database \033[1m$DATABASE_NAME\033[m (UTF-8 support - utf8)" - mysql $MYSQL_CREDENTIAL_ARGS -N -s -e \ + ${mysql_command} $MYSQL_CREDENTIAL_ARGS -N -s -e \ "CREATE DATABASE $DATABASE_NAME CHARACTER SET utf8 COLLATE utf8_general_ci" > $tmp_log_file 2>&1 if [[ $? -ne 0 ]] ; then @@ -744,7 +788,7 @@ if [[ "$MYSQL_CUR_DISTRIBUTION" = "MySQL" ]] && ([[ $MAJOR_VERSION -gt 8 ]] \ fi echononl " Create database user '$DATABASE_USER' access from locahost" - mysql $MYSQL_CREDENTIAL_ARGS -N -s -e \ + ${mysql_command} $MYSQL_CREDENTIAL_ARGS -N -s -e \ "CREATE USER '$DATABASE_USER'@'localhost' IDENTIFIED WITH mysql_native_password BY '$DATABASE_PASSWD'" \ > $tmp_log_file 2>&1 if [[ $? -ne 0 ]] ; then @@ -759,7 +803,7 @@ if [[ "$MYSQL_CUR_DISTRIBUTION" = "MySQL" ]] && ([[ $MAJOR_VERSION -gt 8 ]] \ for _ip in $IP_ADDRESSES ; do echononl " Create database user '$DATABASE_USER' access from '$_ip' " - mysql $MYSQL_CREDENTIAL_ARGS -N -s -e \ + ${mysql_command} $MYSQL_CREDENTIAL_ARGS -N -s -e \ "CREATE USER '$DATABASE_USER'@'$_ip' IDENTIFIED WITH mysql_native_password BY '$DATABASE_PASSWD'" \ > $tmp_log_file 2>&1 if [[ $? -ne 0 ]] ; then @@ -774,7 +818,7 @@ if [[ "$MYSQL_CUR_DISTRIBUTION" = "MySQL" ]] && ([[ $MAJOR_VERSION -gt 8 ]] \ echononl " Grant full access to user '$DATABASE_USER' on Database '$DATABASE_NAME'" - mysql $MYSQL_CREDENTIAL_ARGS -N -s -e \ + ${mysql_command} $MYSQL_CREDENTIAL_ARGS -N -s -e \ "GRANT ALL ON ${DATABASE_NAME}.* TO '$DATABASE_USER'@'localhost'" > $tmp_log_file 2>&1 if [[ $? -ne 0 ]] ; then echo_failed @@ -788,7 +832,7 @@ if [[ "$MYSQL_CUR_DISTRIBUTION" = "MySQL" ]] && ([[ $MAJOR_VERSION -gt 8 ]] \ for _ip in $IP_ADDRESSES ; do echononl " Grant full access to user '$DATABASE_USER' on Database '$DATABASE_NAME' from '$_ip'" - mysql $MYSQL_CREDENTIAL_ARGS -N -s -e \ + ${mysql_command} $MYSQL_CREDENTIAL_ARGS -N -s -e \ "GRANT ALL ON ${DATABASE_NAME}.* TO '$DATABASE_USER'@'$_ip'" > $tmp_log_file 2>&1 if [[ $? -ne 0 ]] ; then echo_failed @@ -805,7 +849,7 @@ elif [[ "$MYSQL_CUR_DISTRIBUTION" = "MariaDB" ]] && ([[ $MAJOR_VERSION -gt 10 ]] || ( [[ $MAJOR_VERSION -eq 10 ]] && [[ $MINOR_VERSION -gt 3 ]] )) ; then echononl " Check if user '$DATABASE_USER' already exists for localhost .." - _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 = 'localhost'" 2> $tmp_log_file)" if [[ -z "$_count" ]]; then echo_failed @@ -814,7 +858,7 @@ elif [[ "$MYSQL_CUR_DISTRIBUTION" = "MariaDB" ]] && ([[ $MAJOR_VERSION -gt 10 ]] echo_ok echononl " Create database user '$DATABASE_USER'" - 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 @@ -829,7 +873,7 @@ elif [[ "$MYSQL_CUR_DISTRIBUTION" = "MariaDB" ]] && ([[ $MAJOR_VERSION -gt 10 ]] fi echononl " Grant permissions to access and use the MySQL server to user '$DATABASE_USER'" - mysql $MYSQL_CREDENTIAL_ARGS -N -s -e \ + ${mysql_command} $MYSQL_CREDENTIAL_ARGS -N -s -e \ "GRANT USAGE ON \`$DATABASE_NAME\`.* TO '$DATABASE_USER'@'localhost'" \ > $tmp_log_file 2>&1 if [[ $? -ne 0 ]] ; then @@ -840,7 +884,7 @@ elif [[ "$MYSQL_CUR_DISTRIBUTION" = "MariaDB" ]] && ([[ $MAJOR_VERSION -gt 10 ]] fi echononl " Grant all privileges to a user '$DATABASE_USER' on database '$DATABASE_NAME'" - mysql $MYSQL_CREDENTIAL_ARGS -N -s -e \ + ${mysql_command} $MYSQL_CREDENTIAL_ARGS -N -s -e \ "GRANT ALL privileges ON \`$DATABASE_NAME\`.* TO '$DATABASE_USER'@'localhost'" \ > $tmp_log_file 2>&1 if [[ $? -ne 0 ]] ; then @@ -855,7 +899,7 @@ elif [[ "$MYSQL_CUR_DISTRIBUTION" = "MariaDB" ]] && ([[ $MAJOR_VERSION -gt 10 ]] 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 @@ -864,7 +908,7 @@ elif [[ "$MYSQL_CUR_DISTRIBUTION" = "MariaDB" ]] && ([[ $MAJOR_VERSION -gt 10 ]] 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 @@ -879,7 +923,7 @@ elif [[ "$MYSQL_CUR_DISTRIBUTION" = "MariaDB" ]] && ([[ $MAJOR_VERSION -gt 10 ]] fi echononl " Allow access to user '$DATABASE_USER' on Database '$DATABASE_NAME' from '$_ip'" - mysql $MYSQL_CREDENTIAL_ARGS -N -s -e \ + ${mysql_command} $MYSQL_CREDENTIAL_ARGS -N -s -e \ "GRANT USAGE ON \`${DATABASE_NAME}\`.* TO '$DATABASE_USER'@'$_ip'" > $tmp_log_file 2>&1 if [[ $? -ne 0 ]] ; then echo_failed @@ -889,7 +933,7 @@ elif [[ "$MYSQL_CUR_DISTRIBUTION" = "MariaDB" ]] && ([[ $MAJOR_VERSION -gt 10 ]] fi echononl " Grant all privileges to user '$DATABASE_USER' on database '$DATABASE_NAME' from '$_ip'" - mysql $MYSQL_CREDENTIAL_ARGS -N -s -e \ + ${mysql_command} $MYSQL_CREDENTIAL_ARGS -N -s -e \ "GRANT ALL privileges ON \`$DATABASE_NAME\`.* TO '$DATABASE_USER'@'$_ip'" \ > $tmp_log_file 2>&1 if [[ $? -ne 0 ]] ; then @@ -906,7 +950,7 @@ elif [[ "$MYSQL_CUR_DISTRIBUTION" = "MariaDB" ]] && ([[ $MAJOR_VERSION -gt 10 ]] else echononl " Grant usage to user '$DATABASE_USER' (Creates User..)" - mysql $MYSQL_CREDENTIAL_ARGS -N -s -e \ + ${mysql_command} $MYSQL_CREDENTIAL_ARGS -N -s -e \ "GRANT USAGE ON *.* TO '$DATABASE_USER'@'localhost' IDENTIFIED BY '$DATABASE_PASSWD'" > $tmp_log_file 2>&1 if [[ $? -ne 0 ]] ; then echo_failed @@ -916,7 +960,7 @@ else fi echononl " Grant all privileges to user '$DATABASE_USER' on Database '$DATABASE_NAME'" - mysql $MYSQL_CREDENTIAL_ARGS -N -s -e \ + ${mysql_command} $MYSQL_CREDENTIAL_ARGS -N -s -e \ "GRANT ALL PRIVILEGES ON ${DATABASE_NAME}.* TO '$DATABASE_USER'@'localhost'" > $tmp_log_file 2>&1 if [[ $? -ne 0 ]] ; then echo_failed @@ -930,7 +974,7 @@ else for _ip in $IP_ADDRESSES ; do echononl " Grant usage to user '$DATABASE_USER' access from ${_ip}" - mysql $MYSQL_CREDENTIAL_ARGS -N -s -e \ + ${mysql_command} $MYSQL_CREDENTIAL_ARGS -N -s -e \ "GRANT USAGE ON *.* TO '$DATABASE_USER'@'${_ip}' IDENTIFIED BY '$DATABASE_PASSWD'" > $tmp_log_file 2>&1 if [[ $? -ne 0 ]] ; then echo_failed @@ -940,7 +984,7 @@ else fi echononl " Grant all privileges to user '$DATABASE_USER' on Database '$DATABASE_NAME' from $_ip" - mysql $MYSQL_CREDENTIAL_ARGS -N -s -e \ + ${mysql_command} $MYSQL_CREDENTIAL_ARGS -N -s -e \ "GRANT ALL PRIVILEGES ON ${DATABASE_NAME}.* TO '$DATABASE_USER'@'${_ip}'" > $tmp_log_file 2>&1 if [[ $? -ne 0 ]] ; then echo_failed @@ -957,7 +1001,7 @@ fi # if [[ $MYSQL_CUR_DISTRIBUTION -ge 8 ]] 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)" diff --git a/drop_database.sh b/drop_database.sh index 46b6dfc..70bf6fe 100755 --- a/drop_database.sh +++ b/drop_database.sh @@ -273,6 +273,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 + + if [[ -n "$DATABASE_NAME" ]] ; then if [[ -z "$DATABASE_USER" || -z "$DATABASE_PASSWD" ]] ; then read_file="" @@ -374,7 +390,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 @@ -468,8 +492,26 @@ if $MYSQL_CREDENTIALS_GIVEN ; then 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)" + 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 @@ -519,7 +561,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" @@ -546,6 +588,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 " Drop Database................: $DATABASE_NAME" if $DO_NOT_DELTE_USER ; then echo -e " Drop Database user...........: \033[33mNone\033[m" @@ -577,7 +621,7 @@ if ! $QUIET_MODE ; then fi echononl " Drop database '$DATABASE_NAME'.." -mysql $MYSQL_CREDENTIAL_ARGS -N -s -e "DROP DATABASE $DATABASE_NAME" > $tmp_log_file 2>&1 +${mysql_command} $MYSQL_CREDENTIAL_ARGS -N -s -e "DROP DATABASE $DATABASE_NAME" > $tmp_log_file 2>&1 if [[ $? -ne 0 ]] ; then echo_failed fatal "$(cat $tmp_log_file)" @@ -586,7 +630,7 @@ else fi echononl " Delete all entries for database '$DATABASE_NAME' from table mysql.db .." -mysql $MYSQL_CREDENTIAL_ARGS mysql -N -s -e \ +${mysql_command} $MYSQL_CREDENTIAL_ARGS mysql -N -s -e \ "DELETE FROM db WHERE Db = '$DATABASE_NAME'" > $tmp_log_file 2>&1 if [[ $? -ne 0 ]] ; then echo_failed @@ -599,7 +643,7 @@ fi # - Test if given user is associated with another database # - echononl " Check if db user '$DATABASE_USER' is also associated with another 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 @@ -610,7 +654,7 @@ else warn "Db user '$DATABASE_USER' is already in use.\n So user will not be deleted from table 'mysql.user'." else echononl " Delete username '$DATABASE_USER' from table mysql.user" - 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 @@ -623,7 +667,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)" diff --git a/drop_database_user.sh b/drop_database_user.sh index 8e2703e..e411654 100755 --- a/drop_database_user.sh +++ b/drop_database_user.sh @@ -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)" diff --git a/drop_tables.sh b/drop_tables.sh index d724797..4c3df36 100755 --- a/drop_tables.sh +++ b/drop_tables.sh @@ -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") diff --git a/dump_database.sh b/dump_database.sh index 5f382a5..3164e7a 100755 --- a/dump_database.sh +++ b/dump_database.sh @@ -82,6 +82,7 @@ usage() { -c "u root -p ''" -c "--login-path=local" + -c "--login-path=mysql-5.7" -c "--defaults-file=/usr/local/mysql/sys-maint.cnf" -c "-u root -S /run/mysqld/mysqld.sock" @@ -142,16 +143,16 @@ clean_up() { fi if [[ -n "$CUR_AUTOCOMMIT" ]] ; then - mysql $DATABASE_CREDENTIALS_ARGS -N -s -e "SET GLOBAL autocommit='$CUR_AUTOCOMMIT'" > /dev/null 2>&1 + ${mysql_command} $DATABASE_CREDENTIALS_ARGS -N -s -e "SET GLOBAL autocommit='$CUR_AUTOCOMMIT'" > /dev/null 2>&1 fi if [[ -n "$CUR_FOREIGN_KEY_CHECKS" ]] ; then - mysql $DATABASE_CREDENTIALS_ARGS -N -s -e "SET GLOBAL autocommit='$CUR_FOREIGN_KEY_CHECKS'" > /dev/null 2>&1 + ${mysql_command} $DATABASE_CREDENTIALS_ARGS -N -s -e "SET GLOBAL autocommit='$CUR_FOREIGN_KEY_CHECKS'" > /dev/null 2>&1 fi if [[ -n "$CUR_UNIQUE_CHECKS" ]] ; then - mysql $DATABASE_CREDENTIALS_ARGS -N -s -e "SET GLOBAL autocommit='$CUR_UNIQUE_CHECKS'" > /dev/null 2>&1 + ${mysql_command} $DATABASE_CREDENTIALS_ARGS -N -s -e "SET GLOBAL autocommit='$CUR_UNIQUE_CHECKS'" > /dev/null 2>&1 fi if [[ -n "$CUR_INNODB_FLUSH_LOG_AT_TRX_COMMIT" ]] ; then - mysql $DATABASE_CREDENTIALS_ARGS -N -s -e "SET GLOBAL autocommit='$CUR_INNODB_FLUSH_LOG_AT_TRX_COMMIT'" > /dev/null 2>&1 + ${mysql_command} $DATABASE_CREDENTIALS_ARGS -N -s -e "SET GLOBAL autocommit='$CUR_INNODB_FLUSH_LOG_AT_TRX_COMMIT'" > /dev/null 2>&1 fi # Perform program exit housekeeping @@ -445,6 +446,37 @@ else NON_INTERACTIVE_MODE=true 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 + +echononl " Get DUMP command.." +mysqldump_command="$(which mysqldump)" +if [[ $? -eq 0 ]]; then + echo_ok +else + + if [[ -x "/usr/local/mysql/bin/mysqldump" ]]; then + mysqldump_command="/usr/local/mysql/bin/mysqldump" + echo_ok + else + echo_failed + fatal "$(cat $tmp_log_file)" + fi +fi + + # ---------- # Read Configurations from $conf_file @@ -515,46 +547,47 @@ if $BATCH_MODE ; then fatal "No Database given \033[m(Option -d)\033[1m!" fi - if [[ -z "$DATABASE_CREDENTIALS_ARGS" ]] && [[ -z "$DATABASE_SERVER" ]]; then +# if [[ -z "$DATABASE_CREDENTIALS_ARGS" ]] && [[ -z "$DATABASE_SERVER" ]]; then +# +# # Try to detect local MySQL Installation +# # +# detect_mysql_version +# +# MAJOR_VERSION="$MYSQL_MAJOR_VERSION" +# MINOR_VERSION="$MYSQL_MINOR_VERSION" +# PATCH_LEVEL="$MYSQL_PATCH_LEVEL" +# +# if [[ "$MYSQL_CUR_DISTRIBUTION" = "MariaDB" ]] && ([[ $MAJOR_VERSION -gt 10 ]] \ +# || ( [[ $MAJOR_VERSION -eq 10 ]] && [[ $MINOR_VERSION -gt 3 ]] )) ; then +# if [[ -S "/tmp/mysql.sock" ]]; then +# DATABASE_CREDENTIALS_ARGS="-u root -S /tmp/mysql.sock" +# elif [[ -S "/run/mysqld/mysqld.sock" ]]; then +# DATABASE_CREDENTIALS_ARGS="-u root -S /run/mysqld/mysqld.sock" +# elif [[ -S "/var/run/mysqld/mysqld.sock" ]]; then +# DATABASE_CREDENTIALS_ARGS="-u root -S /var/run/mysqld/mysqld.sock" +# else +# fatal "Parameter 'DATABASE_CREDENTIALS_ARGS' cannot be determined automated. +# +# Use configuration file "$conf_file" or commandline Parameter or set +# thr mysql credentials." +# fi +# else +# if $(${mysql_command} --login-path=local -e ";" > /dev/null 2>&1) ; then +# DATABASE_CREDENTIALS_ARGS="--login-path=local" +# elif [[ -f "/usr/local/mysql/sys-maint.cnf" ]] ; then +# DATABASE_CREDENTIALS_ARGS="--defaults-file=/usr/local/mysql/sys-maint.cnf" +# elif [[ -f "/etc/mysql/debian.cnf" ]] ; then +# DATABASE_CREDENTIALS_ARGS="--defaults-file=/etc/mysql/debian.cnf" +# else +# fatal "Parameter 'DATABASE_CREDENTIALS_ARGS' cannot be determined automated. +# +# Use configuration file "$conf_file" to set +# parameter manually." +# fi +# fi +# fi - # Try to detect local MySQL Installation - # - detect_mysql_version - - MAJOR_VERSION="$MYSQL_MAJOR_VERSION" - MINOR_VERSION="$MYSQL_MINOR_VERSION" - PATCH_LEVEL="$MYSQL_PATCH_LEVEL" - - if [[ "$MYSQL_CUR_DISTRIBUTION" = "MariaDB" ]] && ([[ $MAJOR_VERSION -gt 10 ]] \ - || ( [[ $MAJOR_VERSION -eq 10 ]] && [[ $MINOR_VERSION -gt 3 ]] )) ; then - if [[ -S "/tmp/mysql.sock" ]]; then - DATABASE_CREDENTIALS_ARGS="-u root -S /tmp/mysql.sock" - elif [[ -S "/run/mysqld/mysqld.sock" ]]; then - DATABASE_CREDENTIALS_ARGS="-u root -S /run/mysqld/mysqld.sock" - elif [[ -S "/var/run/mysqld/mysqld.sock" ]]; then - DATABASE_CREDENTIALS_ARGS="-u root -S /var/run/mysqld/mysqld.sock" - else - fatal "Parameter 'DATABASE_CREDENTIALS_ARGS' cannot be determined automated. - - Use configuration file "$conf_file" or commandline Parameter or set - thr mysql credentials." - fi - else - if $(mysql --login-path=local -e ";" > /dev/null 2>&1) ; then - DATABASE_CREDENTIALS_ARGS="--login-path=local" - elif [[ -f "/usr/local/mysql/sys-maint.cnf" ]] ; then - DATABASE_CREDENTIALS_ARGS="--defaults-file=/usr/local/mysql/sys-maint.cnf" - elif [[ -f "/etc/mysql/debian.cnf" ]] ; then - DATABASE_CREDENTIALS_ARGS="--defaults-file=/etc/mysql/debian.cnf" - else - fatal "Parameter 'DATABASE_CREDENTIALS_ARGS' cannot be determined automated. - - Use configuration file "$conf_file" to set - parameter manually." - fi - fi - - elif [[ -z "$DATABASE_CREDENTIALS_ARGS" ]] && [[ -n "$DATABASE_SERVER" ]]; then + if [[ -z "$DATABASE_CREDENTIALS_ARGS" ]] && [[ -n "$DATABASE_SERVER" ]]; then fatal "Cannot detect database credentials on remote machines. You have to set Parameter '-c'" fi @@ -564,7 +597,7 @@ else echo "" echo -e "\033[32m--\033[m" echo "" - echo "Insert Database Server which should be created.." + echo "Insert Database Server from which should dump should be created.." echo "" echo "" echo -e " \033[33mType to accept the default (localhost).\033[m" @@ -597,33 +630,6 @@ else if $DATABASE_CREDENTIALS_NEEDED ; then - # Try to detect local MySQL Installation - # - detect_mysql_version - - MAJOR_VERSION="$MYSQL_MAJOR_VERSION" - MINOR_VERSION="$MYSQL_MINOR_VERSION" - PATCH_LEVEL="$MYSQL_PATCH_LEVEL" - - if [[ "$MYSQL_CUR_DISTRIBUTION" = "MariaDB" ]] && ([[ $MAJOR_VERSION -gt 10 ]] \ - || ( [[ $MAJOR_VERSION -eq 10 ]] && [[ $MINOR_VERSION -gt 3 ]] )) ; then - if [[ -S "/tmp/mysql.sock" ]]; then - _DATABASE_CREDENTIALS_ARGS="-u root -S /tmp/mysql.sock" - elif [[ -S "/run/mysqld/mysqld.sock" ]]; then - _DATABASE_CREDENTIALS_ARGS="-u root -S /run/mysqld/mysqld.sock" - elif [[ -S "/var/run/mysqld/mysqld.sock" ]]; then - _DATABASE_CREDENTIALS_ARGS="-u root -S /var/run/mysqld/mysqld.sock" - fi - else - if $(mysql --login-path=local -e ";" > /dev/null 2>&1) ; then - _DATABASE_CREDENTIALS_ARGS="--login-path=local" - elif [[ -f "/usr/local/mysql/sys-maint.cnf" ]] ; then - _DATABASE_CREDENTIALS_ARGS="--defaults-file=/usr/local/mysql/sys-maint.cnf" - elif [[ -f "/etc/mysql/debian.cnf" ]] ; then - _DATABASE_CREDENTIALS_ARGS="--defaults-file=/etc/mysql/debian.cnf" - fi - fi - echo "" echo -e "\033[32m--\033[m" echo "" @@ -638,6 +644,7 @@ else \033[33m-u root -p''\033[m \033[33m--login-path=local\033[m + \033[33m--login-path=mysql-5.7\033[m \033[33m--defaults-file=/usr/local/mysql/sys-maint.cnf\033[m \033[33m-u root -S /run/mysqld/mysqld.sock\033[m" echo "" @@ -694,6 +701,124 @@ else fi # if $BATCH_MODE ; then +echo "" +echo -e "\033[32m--\033[m" +echo "" +echononl "Check connection to Database Server.." +if [[ -n "$DATABASE_SERVER" ]] ; then + if ! $(${mysql_command} -h $DATABASE_SERVER $DATABASE_CREDENTIALS_ARGS -e ";" > /dev/null 2> $log_file) ; 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" + mysqldump_command="/usr/local/mysql/bin/mysqldump" + else + fatal "$(cat $log_file)" + fi + else + fatal "$(cat $log_file)" + fi + fi +else + if ! $(${mysql_command} $DATABASE_CREDENTIALS_ARGS -e ";" > /dev/null 2> $log_file) ; 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" + mysqldump_command="/usr/local/mysql/bin/mysqldump" + else + fatal "$(cat $log_file)" + fi + else + fatal "$(cat $log_file)" + fi + fi +fi + + +if [[ -n "$DATABASE_CREDENTIALS_ARGS" ]] ; then + + # - Get MySQL Version + # - + echo "" + echo -e "\033[32m--\033[m" + echo "" + echononl "Get MySQL Version" + _version="$(${mysql_command} $DATABASE_CREDENTIALS_ARGS -N -s -e "SELECT VERSION()" 2> $log_file)" + if [[ $? -ne 0 ]] ; then + echo_failed + fatal "$(cat $log_file)" + else + echo_ok + fi + + echo "" + echo "_version: $_version" + echo "" + echo "" + echo "" + + IFS='.' read -r -a version_arr <<< "$_version" + declare -i MAJOR_VERSION="${version_arr[0]}" + declare -i MINOR_VERSION="${version_arr[1]}" + _path_level="${version_arr[2]}" + declare -i PATCH_LEVEL="${_path_level%%-*}" + + ## - Get current MySQL Distribution + ## - + echononl " Get current MySQL distribution .." + if [[ -z "$_version" ]]; then + echo_failed + fatal "No installed MySQL server or distribution found!" + elif [[ "$_version" =~ MariaDB ]]; then + MYSQL_CUR_DISTRIBUTION="MariaDB" + else + MYSQL_CUR_DISTRIBUTION="MySQL" + fi + echo_ok + echo "" + echo -e "\033[32m--\033[m" + echo "" + +else + # Try to detect local MySQL Installation + # + detect_mysql_version + + MAJOR_VERSION="$MYSQL_MAJOR_VERSION" + MINOR_VERSION="$MYSQL_MINOR_VERSION" + PATCH_LEVEL="$MYSQL_PATCH_LEVEL" + + if [[ "$MYSQL_CUR_DISTRIBUTION" = "MariaDB" ]] && ([[ $MAJOR_VERSION -gt 10 ]] \ + || ( [[ $MAJOR_VERSION -eq 10 ]] && [[ $MINOR_VERSION -gt 3 ]] )) ; then + if [[ -S "/tmp/mysql.sock" ]]; then + DATABASE_CREDENTIALS_ARGS="-u root -S /tmp/mysql.sock" + elif [[ -S "/run/mysqld/mysqld.sock" ]]; then + DATABASE_CREDENTIALS_ARGS="-u root -S /run/mysqld/mysqld.sock" + elif [[ -S "/var/run/mysqld/mysqld.sock" ]]; then + DATABASE_CREDENTIALS_ARGS="-u root -S /var/run/mysqld/mysqld.sock" + else + fatal "Parameter 'DATABASE_CREDENTIALS_ARGS' cannot be determined automated. + + Use configuration file "$conf_file" or commandline Parameter or set + thr mysql credentials." + fi + else + if $(${mysql_command} --login-path=local -e ";" > /dev/null 2>&1) ; then + DATABASE_CREDENTIALS_ARGS="--login-path=local" + elif [[ -f "/usr/local/mysql/sys-maint.cnf" ]] ; then + DATABASE_CREDENTIALS_ARGS="--defaults-file=/usr/local/mysql/sys-maint.cnf" + elif [[ -f "/etc/mysql/debian.cnf" ]] ; then + DATABASE_CREDENTIALS_ARGS="--defaults-file=/etc/mysql/debian.cnf" + else + fatal "Parameter 'DATABASE_CREDENTIALS_ARGS' cannot be determined automated. + + Use configuration file "$conf_file" to set + parameter manually." + fi + fi + +fi + + if ! $QUIET_MODE ; then echo "" echo "" @@ -708,6 +833,9 @@ if ! $QUIET_MODE ; then echo " MySQL Version................: ${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_LEVEL}" fi echo "" + echo " MySQL Command................: ${mysql_command}" + echo " DUMP Commande................: ${mysqldump_command}" + echo "" if [[ -n "$DATABASE_SERVER" ]] ; then echo " Database server..............: $DATABASE_SERVER" else @@ -756,11 +884,11 @@ fi echononl " Check connection to Database Server.." if [[ -n "$DATABASE_SERVER" ]] ; then - if ! $(mysql -h $DATABASE_SERVER $DATABASE_CREDENTIALS_ARGS -e ";" > /dev/null 2>&1) ; then + if ! $(${mysql_command} -h $DATABASE_SERVER $DATABASE_CREDENTIALS_ARGS -e ";" > /dev/null 2>&1) ; then fatal "Cannot connect to Database Server '$DATABASE_SERVER'!" fi else - if ! $(mysql $DATABASE_CREDENTIALS_ARGS -e ";" > /dev/null 2>&1) ; then + if ! $(${mysql_command} $DATABASE_CREDENTIALS_ARGS -e ";" > /dev/null 2>&1) ; then fatal "Cannot connect to Database Server!" fi fi @@ -768,11 +896,11 @@ echo_done echononl " Check connection to Database '$DATABASE_NAME'.." if [[ -n "$DATABASE_SERVER" ]] ; then - if ! $(mysql -h $DATABASE_SERVER $DATABASE_CREDENTIALS_ARGS $DATABASE_NAME -e ";" > /dev/null 2>&1) ; then + if ! $(${mysql_command} -h $DATABASE_SERVER $DATABASE_CREDENTIALS_ARGS $DATABASE_NAME -e ";" > /dev/null 2>&1) ; then fatal "Cannot connect to Database '$DATABASE_NAME'!" fi else - if ! $(mysql $DATABASE_CREDENTIALS_ARGS $DATABASE_NAME -e ";" > /dev/null 2>&1) ; then + if ! $(${mysql_command} $DATABASE_CREDENTIALS_ARGS $DATABASE_NAME -e ";" > /dev/null 2>&1) ; then fatal "Cannot connect to Database '$DATABASE_NAME'!" fi fi @@ -832,7 +960,7 @@ blank_line # - GET current (global) Autocommit value # - echononl " GET current (global) value \033[1mautocommit\033[m" -CUR_AUTOCOMMIT="$(mysql $DATABASE_CREDENTIALS_ARGS -N -s -e "SHOW GLOBAL VARIABLES LIKE 'autocommit'" | awk '{print$2}')" >> $log_file 2>&1 +CUR_AUTOCOMMIT="$(${mysql_command} $DATABASE_CREDENTIALS_ARGS -N -s -e "SHOW GLOBAL VARIABLES LIKE 'autocommit'" | awk '{print$2}')" >> $log_file 2>&1 if [[ $? -eq 0 ]];then echo_ok else @@ -843,7 +971,7 @@ fi # - GET current (global) value for 'foreign_key_checks' # - echononl " GET current (global) value \033[1mforeign_key_checks\033[m" -CUR_FOREIGN_KEY_CHECKS="$(mysql $DATABASE_CREDENTIALS_ARGS -N -s -e "SHOW GLOBAL VARIABLES LIKE 'foreign_key_checks'" | awk '{print$2}')" >> $log_file 2>&1 +CUR_FOREIGN_KEY_CHECKS="$(${mysql_command} $DATABASE_CREDENTIALS_ARGS -N -s -e "SHOW GLOBAL VARIABLES LIKE 'foreign_key_checks'" | awk '{print$2}')" >> $log_file 2>&1 if [[ $? -eq 0 ]];then echo_ok else @@ -854,7 +982,7 @@ fi # - GET current (global) value for 'unique_checks' # - echononl " GET current (global) value \033[1munique_checks\033[m" -CUR_UNIQUE_CHECKS="$(mysql $DATABASE_CREDENTIALS_ARGS -N -s -e "SHOW GLOBAL VARIABLES LIKE 'unique_checks'" | awk '{print$2}')" >> $log_file 2>&1 +CUR_UNIQUE_CHECKS="$(${mysql_command} $DATABASE_CREDENTIALS_ARGS -N -s -e "SHOW GLOBAL VARIABLES LIKE 'unique_checks'" | awk '{print$2}')" >> $log_file 2>&1 if [[ $? -eq 0 ]];then echo_ok else @@ -865,7 +993,7 @@ fi # - GET current (global) value for 'innodb_flush_log_at_trx_commit' # - echononl " GET current (global) value \033[1minnodb_flush_log_at_trx_commit\033[m" -CUR_INNODB_FLUSH_LOG_AT_TRX_COMMIT="$(mysql $DATABASE_CREDENTIALS_ARGS -N -s -e "SHOW GLOBAL VARIABLES LIKE 'innodb_flush_log_at_trx_commit'" | awk '{print$2}')" >> $log_file 2>&1 +CUR_INNODB_FLUSH_LOG_AT_TRX_COMMIT="$(${mysql_command} $DATABASE_CREDENTIALS_ARGS -N -s -e "SHOW GLOBAL VARIABLES LIKE 'innodb_flush_log_at_trx_commit'" | awk '{print$2}')" >> $log_file 2>&1 if [[ $? -eq 0 ]];then echo_ok else @@ -876,7 +1004,7 @@ fi # - GET current (global) value for 'max_allowed_packet' # - echononl " GET current (global) value \033[1mmax_allowed_packet\033[m" -CUR_MAX_ALLOWED_PACKET="$(mysql $DATABASE_CREDENTIALS_ARGS -N -s -e "SHOW GLOBAL VARIABLES LIKE 'max_allowed_packet'" | awk '{print$2}')" >> $log_file 2>&1 +CUR_MAX_ALLOWED_PACKET="$(${mysql_command} $DATABASE_CREDENTIALS_ARGS -N -s -e "SHOW GLOBAL VARIABLES LIKE 'max_allowed_packet'" | awk '{print$2}')" >> $log_file 2>&1 if [[ $? -eq 0 ]];then echo_ok else @@ -887,7 +1015,7 @@ fi blank_line echononl " Set Autocommit to OFF" -mysql $DATABASE_CREDENTIALS_ARGS -N -s -e "SET GLOBAL autocommit='OFF'" >> $log_file 2>&1 +${mysql_command} $DATABASE_CREDENTIALS_ARGS -N -s -e "SET GLOBAL autocommit='OFF'" >> $log_file 2>&1 if [[ $? -eq 0 ]];then echo_ok else @@ -896,7 +1024,7 @@ else fi echononl " Set foreign_key_checks to OFF" -mysql $DATABASE_CREDENTIALS_ARGS -N -s -e "SET GLOBAL foreign_key_checks='OFF'" >> $log_file 2>&1 +${mysql_command} $DATABASE_CREDENTIALS_ARGS -N -s -e "SET GLOBAL foreign_key_checks='OFF'" >> $log_file 2>&1 if [[ $? -eq 0 ]];then echo_ok else @@ -905,7 +1033,7 @@ else fi echononl " Set unique_checks to OFF" -mysql $DATABASE_CREDENTIALS_ARGS -N -s -e "SET GLOBAL unique_checks='OFF'" >> $log_file 2>&1 +${mysql_command} $DATABASE_CREDENTIALS_ARGS -N -s -e "SET GLOBAL unique_checks='OFF'" >> $log_file 2>&1 if [[ $? -eq 0 ]];then echo_ok else @@ -914,7 +1042,7 @@ else fi echononl " Set innodb_flush_log_at_trx_commit to 2" -mysql $DATABASE_CREDENTIALS_ARGS -N -s -e "SET GLOBAL innodb_flush_log_at_trx_commit=2" >> $log_file 2>&1 +${mysql_command} $DATABASE_CREDENTIALS_ARGS -N -s -e "SET GLOBAL innodb_flush_log_at_trx_commit=2" >> $log_file 2>&1 if [[ $? -eq 0 ]];then echo_ok else @@ -923,7 +1051,7 @@ else fi echononl " Set max_allowed_packet to 1G" -mysql $DATABASE_CREDENTIALS_ARGS -N -s -e "SET GLOBAL max_allowed_packet=1073741824" >> $log_file 2>&1 +${mysql_command} $DATABASE_CREDENTIALS_ARGS -N -s -e "SET GLOBAL max_allowed_packet=1073741824" >> $log_file 2>&1 if [[ $? -eq 0 ]];then echo_ok else @@ -944,9 +1072,9 @@ fi echononl " Dump Database '${DATABASE_NAME}'.." b_timestamp=$(date +"%s") if [[ -n "$DATABASE_SERVER" ]] ; then - mysqldump -h $DATABASE_SERVER $DATABASE_CREDENTIALS_ARGS $DATABASE_NAME > ${DATABASE_DUMP_FOLDER}/${DATABASE_DUMP_FILEi} 2> $log_file + ${mysqldump_command} -h $DATABASE_SERVER $DATABASE_CREDENTIALS_ARGS $DATABASE_NAME > ${DATABASE_DUMP_FOLDER}/${DATABASE_DUMP_FILEi} 2> $log_file else - mysqldump $DATABASE_CREDENTIALS_ARGS $DATABASE_NAME > ${DATABASE_DUMP_FOLDER}/${DATABASE_DUMP_FILE} 2> $log_file + ${mysqldump_command} $DATABASE_CREDENTIALS_ARGS $DATABASE_NAME > ${DATABASE_DUMP_FOLDER}/${DATABASE_DUMP_FILE} 2> $log_file fi retval=$? e_timestamp=$(date +"%s") @@ -974,7 +1102,7 @@ if ! $QUIET_MODE ; then fi echononl " Set Autocommit to $CUR_AUTOCOMMIT" -mysql $DATABASE_CREDENTIALS_ARGS -N -s -e "SET GLOBAL autocommit='$CUR_AUTOCOMMIT'" >> $log_file 2>&1 +${mysql_command} $DATABASE_CREDENTIALS_ARGS -N -s -e "SET GLOBAL autocommit='$CUR_AUTOCOMMIT'" >> $log_file 2>&1 if [[ $? -eq 0 ]];then echo_ok CUR_AUTOCOMMIT="" @@ -984,7 +1112,7 @@ else fi echononl " Set foreign_key_checks to $CUR_FOREIGN_KEY_CHECKS" -mysql $DATABASE_CREDENTIALS_ARGS -N -s -e "SET GLOBAL foreign_key_checks='$CUR_FOREIGN_KEY_CHECKS'" >> $log_file 2>&1 +${mysql_command} $DATABASE_CREDENTIALS_ARGS -N -s -e "SET GLOBAL foreign_key_checks='$CUR_FOREIGN_KEY_CHECKS'" >> $log_file 2>&1 if [[ $? -eq 0 ]];then echo_ok CUR_FOREIGN_KEY_CHECKS="" @@ -994,7 +1122,7 @@ else fi echononl " Set unique_checks to $CUR_UNIQUE_CHECKS" -mysql $DATABASE_CREDENTIALS_ARGS -N -s -e "SET GLOBAL unique_checks='$CUR_UNIQUE_CHECKS'" >> $log_file 2>&1 +${mysql_command} $DATABASE_CREDENTIALS_ARGS -N -s -e "SET GLOBAL unique_checks='$CUR_UNIQUE_CHECKS'" >> $log_file 2>&1 if [[ $? -eq 0 ]];then echo_ok CUR_UNIQUE_CHECKS="" @@ -1004,7 +1132,7 @@ else fi echononl " Set innodb_flush_log_at_trx_commit to $CUR_INNODB_FLUSH_LOG_AT_TRX_COMMIT" -mysql $DATABASE_CREDENTIALS_ARGS -N -s -e "SET GLOBAL innodb_flush_log_at_trx_commit=$CUR_INNODB_FLUSH_LOG_AT_TRX_COMMIT" >> $log_file 2>&1 +${mysql_command} $DATABASE_CREDENTIALS_ARGS -N -s -e "SET GLOBAL innodb_flush_log_at_trx_commit=$CUR_INNODB_FLUSH_LOG_AT_TRX_COMMIT" >> $log_file 2>&1 if [[ $? -eq 0 ]];then echo_ok CUR_INNODB_FLUSH_LOG_AT_TRX_COMMIT="" @@ -1014,7 +1142,7 @@ else fi echononl " Set max_allowed_packet to $CUR_MAX_ALLOWED_PACKET" -mysql $DATABASE_CREDENTIALS_ARGS -N -s -e "SET GLOBAL max_allowed_packet=$CUR_MAX_ALLOWED_PACKET" >> $log_file 2>&1 +${mysql_command} $DATABASE_CREDENTIALS_ARGS -N -s -e "SET GLOBAL max_allowed_packet=$CUR_MAX_ALLOWED_PACKET" >> $log_file 2>&1 if [[ $? -eq 0 ]];then echo_ok CUR_MAX_ALLOWED_PACKET="" diff --git a/flush_host_cache.sh b/flush_host_cache.sh index e4da7d1..89f99dc 100755 --- a/flush_host_cache.sh +++ b/flush_host_cache.sh @@ -143,7 +143,7 @@ detect_mysql_version () { mysqladmin=`realpath $(which mysqladmin) 2>/dev/null` if [ -z "$mysqladmin" ]; then if [ -x "/usr/local/mysql/bin/mysqladmin" ]; then - mysql=/usr/local/mysql/bin/mysqladmin + mysqladmin=/usr/local/mysql/bin/mysqladmin else echo echo -e "\t[ Error ]: \"mysqladmin\" not found !!!" @@ -237,12 +237,21 @@ while [[ $index_arr -lt ${#mysql_credential_args_arr[@]} ]] ; do mysql_credential_args="${_val_arr[1]}" echononl " [ ${mysql_version} ]: Flush host cache.." - $mysqladmin $mysql_credential_args flush-hosts + $mysqladmin $mysql_credential_args flush-hosts 2> $tmp_log_file if [[ $? -eq 0 ]]; then echo_ok else - echo_failed - error "$(cat $tmp_log_file)" + if [[ "$(cat $tmp_log_file)" =~ "unknown variable 'login-path" ]] ; then + if [[ -x "/usr/local/mysql/bin/mysqladmin" ]] ; then + /usr/local/mysql/bin/mysqladmin $mysql_credential_args flush-hosts + if [[ $? -ne 0 ]] ; then + echo_failed + error "$(cat $tmp_log_file)" + else + echo_ok + fi + fi + fi fi (( index_arr++ )) diff --git a/flush_query_cache.sh b/flush_query_cache.sh index 126d44e..2af6a0d 100755 --- a/flush_query_cache.sh +++ b/flush_query_cache.sh @@ -242,8 +242,17 @@ while [[ $index_arr -lt ${#mysql_credential_args_arr[@]} ]] ; do if [[ $? -eq 0 ]]; then echo_ok else - echo_failed - error "$(cat $tmp_log_file)" + if [[ "$(cat $tmp_log_file)" =~ "unknown variable 'login-path" ]] ; then + if [[ -x "/usr/local/mysql/bin/mysql" ]] ; then + /usr/local/mysql/bin/mysql $mysql_credential_args -N -s -e "FLUSH QUERY CACHE" > $tmp_log_file 2>&1 + if [[ $? -ne 0 ]] ; then + echo_failed + error "$(cat $tmp_log_file)" + else + echo_ok + fi + fi + fi fi (( index_arr++ )) diff --git a/grant_backup_privileges_to_user.sh b/grant_backup_privileges_to_user.sh index bac91db..739dec4 100755 --- a/grant_backup_privileges_to_user.sh +++ b/grant_backup_privileges_to_user.sh @@ -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)" diff --git a/grant_dbaccess_to_user.sh b/grant_dbaccess_to_user.sh index 4588b71..8937f0e 100755 --- a/grant_dbaccess_to_user.sh +++ b/grant_dbaccess_to_user.sh @@ -274,6 +274,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 + + if [[ -n "$DATABASE_NAME" ]] ; then if [[ -z "$DATABASE_USER" || -z "$DATABASE_PASSWD" ]] ; then read_file="" @@ -375,7 +391,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 @@ -514,10 +538,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 @@ -567,7 +609,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" @@ -596,6 +638,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 name................: $DATABASE_NAME" echo " Database user................: $DATABASE_USER" echo " Database password............: $DATABASE_PASSWD" @@ -637,7 +681,7 @@ fi # - Check if Database already exists # - -_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 [[ "$_result" != "$DATABASE_NAME" ]] ; then fatal "Database '$DATABASE_NAME' does not exists" fi @@ -645,7 +689,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 @@ -670,7 +714,7 @@ if [[ "$MYSQL_CUR_DISTRIBUTION" = "MySQL" ]] && ([[ $MAJOR_VERSION -gt 8 ]] \ 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 WITH mysql_native_password BY '$DATABASE_PASSWD'" \ > $tmp_log_file 2>&1 if [[ $? -ne 0 ]] ; then @@ -688,7 +732,7 @@ if [[ "$MYSQL_CUR_DISTRIBUTION" = "MySQL" ]] && ([[ $MAJOR_VERSION -gt 8 ]] \ 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 @@ -697,7 +741,7 @@ if [[ "$MYSQL_CUR_DISTRIBUTION" = "MySQL" ]] && ([[ $MAJOR_VERSION -gt 8 ]] \ echo_ok echononl " Create database user '$DATABASE_USER' access from '$_ip' " - mysql $MYSQL_CREDENTIAL_ARGS -N -s -e \ + ${mysql_command} $MYSQL_CREDENTIAL_ARGS -N -s -e \ "CREATE USER '$DATABASE_USER'@'$_ip' IDENTIFIED WITH mysql_native_password BY '$DATABASE_PASSWD'" \ > $tmp_log_file 2>&1 if [[ $? -ne 0 ]] ; then @@ -715,7 +759,7 @@ if [[ "$MYSQL_CUR_DISTRIBUTION" = "MySQL" ]] && ([[ $MAJOR_VERSION -gt 8 ]] \ echononl " Grant full access to user '$DATABASE_USER' on Database '$DATABASE_NAME'" - mysql $MYSQL_CREDENTIAL_ARGS -N -s -e \ + ${mysql_command} $MYSQL_CREDENTIAL_ARGS -N -s -e \ "GRANT ALL ON ${DATABASE_NAME}.* TO '$DATABASE_USER'@'localhost'" > $tmp_log_file 2>&1 if [[ $? -ne 0 ]] ; then echo_failed @@ -729,7 +773,7 @@ if [[ "$MYSQL_CUR_DISTRIBUTION" = "MySQL" ]] && ([[ $MAJOR_VERSION -gt 8 ]] \ for _ip in $IP_ADDRESSES ; do echononl " Grant full access to user '$DATABASE_USER' on Database '$DATABASE_NAME' from '$_ip'" - mysql $MYSQL_CREDENTIAL_ARGS -N -s -e \ + ${mysql_command} $MYSQL_CREDENTIAL_ARGS -N -s -e \ "GRANT ALL ON ${DATABASE_NAME}.* TO '$DATABASE_USER'@'$_ip'" > $tmp_log_file 2>&1 if [[ $? -ne 0 ]] ; then echo_failed @@ -748,7 +792,7 @@ elif [[ "$MYSQL_CUR_DISTRIBUTION" = "MariaDB" ]] && ([[ $MAJOR_VERSION -gt 10 ]] 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 @@ -762,7 +806,7 @@ elif [[ "$MYSQL_CUR_DISTRIBUTION" = "MariaDB" ]] && ([[ $MAJOR_VERSION -gt 10 ]] fi echononl " Grant permissions to access and use the MySQL server to user '$DATABASE_USER'" - mysql $MYSQL_CREDENTIAL_ARGS -N -s -e \ + ${mysql_command} $MYSQL_CREDENTIAL_ARGS -N -s -e \ "GRANT USAGE ON \`$DATABASE_NAME\`.* TO '$DATABASE_USER'@'localhost'" \ > $tmp_log_file 2>&1 if [[ $? -ne 0 ]] ; then @@ -773,7 +817,7 @@ elif [[ "$MYSQL_CUR_DISTRIBUTION" = "MariaDB" ]] && ([[ $MAJOR_VERSION -gt 10 ]] fi echononl " Grant all privileges to a user '$DATABASE_USER' on database '$DATABASE_NAME'" - mysql $MYSQL_CREDENTIAL_ARGS -N -s -e \ + ${mysql_command} $MYSQL_CREDENTIAL_ARGS -N -s -e \ "GRANT ALL privileges ON \`$DATABASE_NAME\`.* TO '$DATABASE_USER'@'localhost'" \ > $tmp_log_file 2>&1 if [[ $? -ne 0 ]] ; then @@ -788,7 +832,7 @@ elif [[ "$MYSQL_CUR_DISTRIBUTION" = "MariaDB" ]] && ([[ $MAJOR_VERSION -gt 10 ]] 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 @@ -797,7 +841,7 @@ elif [[ "$MYSQL_CUR_DISTRIBUTION" = "MariaDB" ]] && ([[ $MAJOR_VERSION -gt 10 ]] 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 @@ -812,7 +856,7 @@ elif [[ "$MYSQL_CUR_DISTRIBUTION" = "MariaDB" ]] && ([[ $MAJOR_VERSION -gt 10 ]] fi echononl " Allow access to user '$DATABASE_USER' on Database '$DATABASE_NAME' from '$_ip'" - mysql $MYSQL_CREDENTIAL_ARGS -N -s -e \ + ${mysql_command} $MYSQL_CREDENTIAL_ARGS -N -s -e \ "GRANT USAGE ON \`${DATABASE_NAME}\`.* TO '$DATABASE_USER'@'$_ip'" > $tmp_log_file 2>&1 if [[ $? -ne 0 ]] ; then echo_failed @@ -822,7 +866,7 @@ elif [[ "$MYSQL_CUR_DISTRIBUTION" = "MariaDB" ]] && ([[ $MAJOR_VERSION -gt 10 ]] fi echononl " Grant all privileges to user '$DATABASE_USER' on database '$DATABASE_NAME' from '$_ip'" - mysql $MYSQL_CREDENTIAL_ARGS -N -s -e \ + ${mysql_command} $MYSQL_CREDENTIAL_ARGS -N -s -e \ "GRANT ALL privileges ON \`$DATABASE_NAME\`.* TO '$DATABASE_USER'@'$_ip'" \ > $tmp_log_file 2>&1 if [[ $? -ne 0 ]] ; then @@ -839,7 +883,7 @@ elif [[ "$MYSQL_CUR_DISTRIBUTION" = "MariaDB" ]] && ([[ $MAJOR_VERSION -gt 10 ]] else echononl " Grant usage to user '$DATABASE_USER' (Creates User..)" - mysql $MYSQL_CREDENTIAL_ARGS -N -s -e \ + ${mysql_command} $MYSQL_CREDENTIAL_ARGS -N -s -e \ "GRANT USAGE ON *.* TO '$DATABASE_USER'@'localhost' IDENTIFIED BY '$DATABASE_PASSWD'" > $tmp_log_file 2>&1 if [[ $? -ne 0 ]] ; then echo_failed @@ -849,7 +893,7 @@ else fi echononl " Grant all privileges to user '$DATABASE_USER' on Database '$DATABASE_NAME'" - mysql $MYSQL_CREDENTIAL_ARGS -N -s -e \ + ${mysql_command} $MYSQL_CREDENTIAL_ARGS -N -s -e \ "GRANT ALL PRIVILEGES ON ${DATABASE_NAME}.* TO '$DATABASE_USER'@'localhost'" > $tmp_log_file 2>&1 if [[ $? -ne 0 ]] ; then echo_failed @@ -863,7 +907,7 @@ else for _ip in $IP_ADDRESSES ; do echononl " Grant usage to user '$DATABASE_USER' access from ${_ip}" - mysql $MYSQL_CREDENTIAL_ARGS -N -s -e \ + ${mysql_command} $MYSQL_CREDENTIAL_ARGS -N -s -e \ "GRANT USAGE ON *.* TO '$DATABASE_USER'@'${_ip}' IDENTIFIED BY '$DATABASE_PASSWD'" > $tmp_log_file 2>&1 if [[ $? -ne 0 ]] ; then echo_failed @@ -873,7 +917,7 @@ else fi echononl " Grant all privileges to user '$DATABASE_USER' on Database '$DATABASE_NAME' from $_ip" - mysql $MYSQL_CREDENTIAL_ARGS -N -s -e \ + ${mysql_command} $MYSQL_CREDENTIAL_ARGS -N -s -e \ "GRANT ALL PRIVILEGES ON ${DATABASE_NAME}.* TO '$DATABASE_USER'@'${_ip}'" > $tmp_log_file 2>&1 if [[ $? -ne 0 ]] ; then echo_failed @@ -890,7 +934,7 @@ fi # if [[ $MYSQL_CUR_DISTRIBUTION -ge 8 ]] 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)" diff --git a/grant_full_access_to_user.sh b/grant_full_access_to_user.sh index 2442b62..41363c9 100755 --- a/grant_full_access_to_user.sh +++ b/grant_full_access_to_user.sh @@ -287,6 +287,22 @@ if [[ -n "$mysql_credential_args" ]]; then MYSQL_CREDENTIAL_ARGS="$mysql_credential_args" MYSQL_CREDENTIALS_GIVEN=true 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 ! $NON_INTERACTIVE_MODE ; then @@ -313,7 +329,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 @@ -435,10 +459,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 @@ -488,7 +530,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" @@ -517,6 +559,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 "" @@ -558,7 +602,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 @@ -583,7 +627,7 @@ if [[ "$MYSQL_CUR_DISTRIBUTION" = "MySQL" ]] && ([[ $MAJOR_VERSION -gt 8 ]] \ 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 WITH mysql_native_password BY '$DATABASE_PASSWD'" \ > $tmp_log_file 2>&1 if [[ $? -ne 0 ]] ; then @@ -601,7 +645,7 @@ if [[ "$MYSQL_CUR_DISTRIBUTION" = "MySQL" ]] && ([[ $MAJOR_VERSION -gt 8 ]] \ 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 @@ -610,7 +654,7 @@ if [[ "$MYSQL_CUR_DISTRIBUTION" = "MySQL" ]] && ([[ $MAJOR_VERSION -gt 8 ]] \ echo_ok echononl " Create database user '$DATABASE_USER' access from '$_ip' " - mysql $MYSQL_CREDENTIAL_ARGS -N -s -e \ + ${mysql_command} $MYSQL_CREDENTIAL_ARGS -N -s -e \ "CREATE USER '$DATABASE_USER'@'$_ip' IDENTIFIED WITH mysql_native_password BY '$DATABASE_PASSWD'" \ > $tmp_log_file 2>&1 if [[ $? -ne 0 ]] ; then @@ -628,7 +672,7 @@ if [[ "$MYSQL_CUR_DISTRIBUTION" = "MySQL" ]] && ([[ $MAJOR_VERSION -gt 8 ]] \ echononl " Grant full access to user '$DATABASE_USER' on all Databases" - mysql $MYSQL_CREDENTIAL_ARGS -N -s -e \ + ${mysql_command} $MYSQL_CREDENTIAL_ARGS -N -s -e \ "GRANT ALL ON *.* TO '$DATABASE_USER'@'localhost'" > $tmp_log_file 2>&1 if [[ $? -ne 0 ]] ; then echo_failed @@ -642,7 +686,7 @@ if [[ "$MYSQL_CUR_DISTRIBUTION" = "MySQL" ]] && ([[ $MAJOR_VERSION -gt 8 ]] \ for _ip in $IP_ADDRESSES ; do echononl " Grant full access to user '$DATABASE_USER' on all Database from '$_ip'" - mysql $MYSQL_CREDENTIAL_ARGS -N -s -e \ + ${mysql_command} $MYSQL_CREDENTIAL_ARGS -N -s -e \ "GRANT ALL ON *.* TO '$DATABASE_USER'@'$_ip'" > $tmp_log_file 2>&1 if [[ $? -ne 0 ]] ; then echo_failed @@ -661,12 +705,12 @@ elif [[ "$MYSQL_CUR_DISTRIBUTION" = "MariaDB" ]] && ([[ $MAJOR_VERSION -gt 10 ]] echononl " Create database user '$DATABASE_USER' access from locahost" if ! $user_exists ; then - echo "" - echo "mysql $MYSQL_CREDENTIAL_ARGS -N -s -e \"CREATE USER '$DATABASE_USER'@'localhost' IDENTIFIED BY '$DATABASE_PASSWD'\"" - echo "" - #mysql $MYSQL_CREDENTIAL_ARGS -N -s -e \ - # "CREATE USER '$DATABASE_USER'@'localhost' IDENTIFIED BY '$DATABASE_PASSWD'" \ - # > $tmp_log_file 2>&1 + #echo "" + #echo "${mysql_command} $MYSQL_CREDENTIAL_ARGS -N -s -e \"CREATE USER '$DATABASE_USER'@'localhost' IDENTIFIED BY '$DATABASE_PASSWD'\"" + #echo "" + ${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 echo_failed error "$(cat $tmp_log_file)" @@ -678,12 +722,12 @@ elif [[ "$MYSQL_CUR_DISTRIBUTION" = "MariaDB" ]] && ([[ $MAJOR_VERSION -gt 10 ]] fi echononl " Grant permissions to access and use the MySQL server to user '$DATABASE_USER'" - echo "" - echo "mysql $MYSQL_CREDENTIAL_ARGS -N -s -e \"GRANT USAGE ON *.* TO '$DATABASE_USER'@'localhost'\"" - echo "" - #mysql $MYSQL_CREDENTIAL_ARGS -N -s -e \ - # "GRANT USAGE ON *.* TO '$DATABASE_USER'@'localhost'" \ - # > $tmp_log_file 2>&1 + #echo "" + #echo "${mysql_command} $MYSQL_CREDENTIAL_ARGS -N -s -e \"GRANT USAGE ON *.* TO '$DATABASE_USER'@'localhost'\"" + #echo "" + ${mysql_command} $MYSQL_CREDENTIAL_ARGS -N -s -e \ + "GRANT USAGE ON *.* TO '$DATABASE_USER'@'localhost'" \ + > $tmp_log_file 2>&1 if [[ $? -ne 0 ]] ; then echo_failed error "$(cat $tmp_log_file)" @@ -695,7 +739,7 @@ elif [[ "$MYSQL_CUR_DISTRIBUTION" = "MariaDB" ]] && ([[ $MAJOR_VERSION -gt 10 ]] echo "" echo "$MYSQL_CREDENTIAL_ARGS -N -s -e \"GRANT ALL privileges ON *.* TO '$DATABASE_USER'@'localhost'\"" echo "" - #mysql $MYSQL_CREDENTIAL_ARGS -N -s -e \ + #${mysql_command} $MYSQL_CREDENTIAL_ARGS -N -s -e \ # "GRANT ALL privileges ON *.* TO '$DATABASE_USER'@'localhost'" \ # > $tmp_log_file 2>&1 if [[ $? -ne 0 ]] ; then @@ -710,7 +754,7 @@ elif [[ "$MYSQL_CUR_DISTRIBUTION" = "MariaDB" ]] && ([[ $MAJOR_VERSION -gt 10 ]] 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 @@ -719,7 +763,7 @@ elif [[ "$MYSQL_CUR_DISTRIBUTION" = "MariaDB" ]] && ([[ $MAJOR_VERSION -gt 10 ]] 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 @@ -734,7 +778,7 @@ elif [[ "$MYSQL_CUR_DISTRIBUTION" = "MariaDB" ]] && ([[ $MAJOR_VERSION -gt 10 ]] 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 @@ -744,7 +788,7 @@ elif [[ "$MYSQL_CUR_DISTRIBUTION" = "MariaDB" ]] && ([[ $MAJOR_VERSION -gt 10 ]] 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 ALL privileges ON *.* TO '$DATABASE_USER'@'$_ip'" \ > $tmp_log_file 2>&1 if [[ $? -ne 0 ]] ; then @@ -761,7 +805,7 @@ elif [[ "$MYSQL_CUR_DISTRIBUTION" = "MariaDB" ]] && ([[ $MAJOR_VERSION -gt 10 ]] else echononl " Grant usage to user '$DATABASE_USER' (Creates User..)" - mysql $MYSQL_CREDENTIAL_ARGS -N -s -e \ + ${mysql_command} $MYSQL_CREDENTIAL_ARGS -N -s -e \ "GRANT USAGE ON *.* TO '$DATABASE_USER'@'localhost' IDENTIFIED BY '$DATABASE_PASSWD'" > $tmp_log_file 2>&1 if [[ $? -ne 0 ]] ; then echo_failed @@ -771,7 +815,7 @@ else fi echononl " Grant all privileges to user '$DATABASE_USER' on all databases" - mysql $MYSQL_CREDENTIAL_ARGS -N -s -e \ + ${mysql_command} $MYSQL_CREDENTIAL_ARGS -N -s -e \ "GRANT ALL PRIVILEGES ON *.* TO '$DATABASE_USER'@'localhost'" > $tmp_log_file 2>&1 if [[ $? -ne 0 ]] ; then echo_failed @@ -785,7 +829,7 @@ else for _ip in $IP_ADDRESSES ; do echononl " Grant usage to user '$DATABASE_USER' access from ${_ip}" - mysql $MYSQL_CREDENTIAL_ARGS -N -s -e \ + ${mysql_command} $MYSQL_CREDENTIAL_ARGS -N -s -e \ "GRANT USAGE ON *.* TO '$DATABASE_USER'@'${_ip}' IDENTIFIED BY '$DATABASE_PASSWD'" > $tmp_log_file 2>&1 if [[ $? -ne 0 ]] ; then echo_failed @@ -795,7 +839,7 @@ else 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 ALL PRIVILEGES ON *.* TO '$DATABASE_USER'@'${_ip}'" > $tmp_log_file 2>&1 if [[ $? -ne 0 ]] ; then echo_failed @@ -812,7 +856,7 @@ fi # if [[ $MYSQL_CUR_DISTRIBUTION -ge 8 ]] 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)" diff --git a/optimize_mysql_tables-ND.sh b/optimize_mysql_tables-ND.sh index 3fd4186..a644e6a 100755 --- a/optimize_mysql_tables-ND.sh +++ b/optimize_mysql_tables-ND.sh @@ -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")" diff --git a/optimize_mysql_tables.sh b/optimize_mysql_tables.sh index 7608234..6b34360 100755 --- a/optimize_mysql_tables.sh +++ b/optimize_mysql_tables.sh @@ -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 @@ -427,13 +443,13 @@ while [[ $index_arr -lt ${#mysql_credential_args_arr[@]} ]] ; do echo "" >> $log_file echo -e " [$(date)] Optimize tables in database '${db}'.." >> $log_file - 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" @@ -459,7 +475,7 @@ while [[ $index_arr -lt ${#mysql_credential_args_arr[@]} ]] ; do 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 @@ -470,7 +486,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 @@ -484,7 +500,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")" diff --git a/repair_mysql_tables.sh b/repair_mysql_tables.sh index 42216f3..537629f 100755 --- a/repair_mysql_tables.sh +++ b/repair_mysql_tables.sh @@ -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")" diff --git a/restore_database.sh b/restore_database.sh index 2d56b92..bcde8c2 100755 --- a/restore_database.sh +++ b/restore_database.sh @@ -81,6 +81,7 @@ usage() { -c "u root -p ''" -c "--login-path=local" + -c "--login-path=mysql-5.7" -c "--defaults-file=/usr/local/mysql/sys-maint.cnf" -c "-u root -S /run/mysqld/mysqld.sock" @@ -141,16 +142,16 @@ clean_up() { fi if [[ -n "$CUR_AUTOCOMMIT" ]] ; then - mysql $DATABASE_CREDENTIALS_ARGS -N -s -e "SET GLOBAL autocommit='$CUR_AUTOCOMMIT'" > /dev/null 2>&1 + ${mysql_command} $DATABASE_CREDENTIALS_ARGS -N -s -e "SET GLOBAL autocommit='$CUR_AUTOCOMMIT'" > /dev/null 2>&1 fi if [[ -n "$CUR_FOREIGN_KEY_CHECKS" ]] ; then - mysql $DATABASE_CREDENTIALS_ARGS -N -s -e "SET GLOBAL autocommit='$CUR_FOREIGN_KEY_CHECKS'" > /dev/null 2>&1 + ${mysql_command} $DATABASE_CREDENTIALS_ARGS -N -s -e "SET GLOBAL autocommit='$CUR_FOREIGN_KEY_CHECKS'" > /dev/null 2>&1 fi if [[ -n "$CUR_UNIQUE_CHECKS" ]] ; then - mysql $DATABASE_CREDENTIALS_ARGS -N -s -e "SET GLOBAL autocommit='$CUR_UNIQUE_CHECKS'" > /dev/null 2>&1 + ${mysql_command} $DATABASE_CREDENTIALS_ARGS -N -s -e "SET GLOBAL autocommit='$CUR_UNIQUE_CHECKS'" > /dev/null 2>&1 fi if [[ -n "$CUR_INNODB_FLUSH_LOG_AT_TRX_COMMIT" ]] ; then - mysql $DATABASE_CREDENTIALS_ARGS -N -s -e "SET GLOBAL autocommit='$CUR_INNODB_FLUSH_LOG_AT_TRX_COMMIT'" > /dev/null 2>&1 + ${mysql_command} $DATABASE_CREDENTIALS_ARGS -N -s -e "SET GLOBAL autocommit='$CUR_INNODB_FLUSH_LOG_AT_TRX_COMMIT'" > /dev/null 2>&1 fi # Perform program exit housekeeping @@ -444,6 +445,21 @@ else NON_INTERACTIVE_MODE=true 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 + # ---------- # Read Configurations from $conf_file @@ -510,46 +526,47 @@ if $BATCH_MODE ; then fatal "No Database given \033[m(Option -d)\033[1m!" fi - if [[ -z "$DATABASE_CREDENTIALS_ARGS" ]] && [[ -z "$DATABASE_SERVER" ]]; then +# if [[ -z "$DATABASE_CREDENTIALS_ARGS" ]] && [[ -z "$DATABASE_SERVER" ]]; then +# +# # Try to detect local MySQL Installation +# # +# detect_mysql_version +# +# MAJOR_VERSION="$MYSQL_MAJOR_VERSION" +# MINOR_VERSION="$MYSQL_MINOR_VERSION" +# PATCH_LEVEL="$MYSQL_PATCH_LEVEL" +# +# if [[ "$MYSQL_CUR_DISTRIBUTION" = "MariaDB" ]] && ([[ $MAJOR_VERSION -gt 10 ]] \ +# || ( [[ $MAJOR_VERSION -eq 10 ]] && [[ $MINOR_VERSION -gt 3 ]] )) ; then +# if [[ -S "/tmp/mysql.sock" ]]; then +# DATABASE_CREDENTIALS_ARGS="-u root -S /tmp/mysql.sock" +# elif [[ -S "/run/mysqld/mysqld.sock" ]]; then +# DATABASE_CREDENTIALS_ARGS="-u root -S /run/mysqld/mysqld.sock" +# elif [[ -S "/var/run/mysqld/mysqld.sock" ]]; then +# DATABASE_CREDENTIALS_ARGS="-u root -S /var/run/mysqld/mysqld.sock" +# else +# fatal "Parameter 'DATABASE_CREDENTIALS_ARGS' cannot be determined automated. +# +# Use configuration file "$conf_file" or commandline Parameter or set +# thr mysql credentials." +# fi +# else +# if $(${mysql_command} --login-path=local -e ";" > /dev/null 2>&1) ; then +# DATABASE_CREDENTIALS_ARGS="--login-path=local" +# elif [[ -f "/usr/local/mysql/sys-maint.cnf" ]] ; then +# DATABASE_CREDENTIALS_ARGS="--defaults-file=/usr/local/mysql/sys-maint.cnf" +# elif [[ -f "/etc/mysql/debian.cnf" ]] ; then +# DATABASE_CREDENTIALS_ARGS="--defaults-file=/etc/mysql/debian.cnf" +# else +# fatal "Parameter 'DATABASE_CREDENTIALS_ARGS' cannot be determined automated. +# +# Use configuration file "$conf_file" to set +# parameter manually." +# fi +# fi +# fi - # Try to detect local MySQL Installation - # - detect_mysql_version - - MAJOR_VERSION="$MYSQL_MAJOR_VERSION" - MINOR_VERSION="$MYSQL_MINOR_VERSION" - PATCH_LEVEL="$MYSQL_PATCH_LEVEL" - - if [[ "$MYSQL_CUR_DISTRIBUTION" = "MariaDB" ]] && ([[ $MAJOR_VERSION -gt 10 ]] \ - || ( [[ $MAJOR_VERSION -eq 10 ]] && [[ $MINOR_VERSION -gt 3 ]] )) ; then - if [[ -S "/tmp/mysql.sock" ]]; then - DATABASE_CREDENTIALS_ARGS="-u root -S /tmp/mysql.sock" - elif [[ -S "/run/mysqld/mysqld.sock" ]]; then - DATABASE_CREDENTIALS_ARGS="-u root -S /run/mysqld/mysqld.sock" - elif [[ -S "/var/run/mysqld/mysqld.sock" ]]; then - DATABASE_CREDENTIALS_ARGS="-u root -S /var/run/mysqld/mysqld.sock" - else - fatal "Parameter 'DATABASE_CREDENTIALS_ARGS' cannot be determined automated. - - Use configuration file "$conf_file" or commandline Parameter or set - thr mysql credentials." - fi - else - if $(mysql --login-path=local -e ";" > /dev/null 2>&1) ; then - DATABASE_CREDENTIALS_ARGS="--login-path=local" - elif [[ -f "/usr/local/mysql/sys-maint.cnf" ]] ; then - DATABASE_CREDENTIALS_ARGS="--defaults-file=/usr/local/mysql/sys-maint.cnf" - elif [[ -f "/etc/mysql/debian.cnf" ]] ; then - DATABASE_CREDENTIALS_ARGS="--defaults-file=/etc/mysql/debian.cnf" - else - fatal "Parameter 'DATABASE_CREDENTIALS_ARGS' cannot be determined automated. - - Use configuration file "$conf_file" to set - parameter manually." - fi - fi - - elif [[ -z "$DATABASE_CREDENTIALS_ARGS" ]] && [[ -n "$DATABASE_SERVER" ]]; then + if [[ -z "$DATABASE_CREDENTIALS_ARGS" ]] && [[ -n "$DATABASE_SERVER" ]]; then fatal "Cannot detect database credentials on remote machines. You have to set Parameter '-c'" fi @@ -559,7 +576,7 @@ else echo "" echo -e "\033[32m--\033[m" echo "" - echo "Insert Database Server which should be created.." + echo "Insert Database Server for which we should restore a database.." echo "" echo "" echo -e " \033[33mType to accept the default (localhost).\033[m" @@ -590,33 +607,6 @@ else fi if $DATABASE_CREDENTIALS_NEEDED ; then - - # Try to detect local MySQL Installation - # - detect_mysql_version - - MAJOR_VERSION="$MYSQL_MAJOR_VERSION" - MINOR_VERSION="$MYSQL_MINOR_VERSION" - PATCH_LEVEL="$MYSQL_PATCH_LEVEL" - - if [[ "$MYSQL_CUR_DISTRIBUTION" = "MariaDB" ]] && ([[ $MAJOR_VERSION -gt 10 ]] \ - || ( [[ $MAJOR_VERSION -eq 10 ]] && [[ $MINOR_VERSION -gt 3 ]] )) ; then - if [[ -S "/tmp/mysql.sock" ]]; then - _DATABASE_CREDENTIALS_ARGS="-u root -S /tmp/mysql.sock" - elif [[ -S "/run/mysqld/mysqld.sock" ]]; then - _DATABASE_CREDENTIALS_ARGS="-u root -S /run/mysqld/mysqld.sock" - elif [[ -S "/var/run/mysqld/mysqld.sock" ]]; then - _DATABASE_CREDENTIALS_ARGS="-u root -S /var/run/mysqld/mysqld.sock" - fi - else - if $(mysql --login-path=local -e ";" > /dev/null 2>&1) ; then - _DATABASE_CREDENTIALS_ARGS="--login-path=local" - elif [[ -f "/usr/local/mysql/sys-maint.cnf" ]] ; then - _DATABASE_CREDENTIALS_ARGS="--defaults-file=/usr/local/mysql/sys-maint.cnf" - elif [[ -f "/etc/mysql/debian.cnf" ]] ; then - _DATABASE_CREDENTIALS_ARGS="--defaults-file=/etc/mysql/debian.cnf" - fi - fi echo "" echo -e "\033[32m--\033[m" @@ -632,6 +622,7 @@ else \033[33m-u root -p''\033[m \033[33m--login-path=local\033[m + \033[33m--login-path=mysql-5.7\033[m \033[33m--defaults-file=/usr/local/mysql/sys-maint.cnf\033[m \033[33m-u root -S /run/mysqld/mysqld.sock\033[m" echo "" @@ -689,6 +680,122 @@ else fi # if $BATCH_MODE ; then +echo "" +echo -e "\033[32m--\033[m" +echo "" +echononl "Check connection to Database Server.." +if [[ -n "$DATABASE_SERVER" ]] ; then + if ! $(${mysql_command} -h $DATABASE_SERVER $DATABASE_CREDENTIALS_ARGS -e ";" > /dev/null 2> $log_file) ; 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" + else + fatal "$(cat $log_file)" + fi + else + fatal "$(cat $log_file)" + fi + fi +else + if ! $(${mysql_command} $DATABASE_CREDENTIALS_ARGS -e ";" > /dev/null 2> $log_file) ; 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" + else + fatal "$(cat $log_file)" + fi + else + fatal "$(cat $log_file)" + fi + fi +fi + + +if [[ -n "$DATABASE_CREDENTIALS_ARGS" ]] ; then + + # - Get MySQL Version + # - + echo "" + echo -e "\033[32m--\033[m" + echo "" + echononl "Get MySQL Version" + _version="$(${mysql_command} $DATABASE_CREDENTIALS_ARGS -N -s -e "SELECT VERSION()" 2> $log_file)" + if [[ $? -ne 0 ]] ; then + echo_failed + fatal "$(cat $log_file)" + else + echo_ok + fi + + echo "" + echo "_version: $_version" + echo "" + echo "" + echo "" + + IFS='.' read -r -a version_arr <<< "$_version" + declare -i MAJOR_VERSION="${version_arr[0]}" + declare -i MINOR_VERSION="${version_arr[1]}" + _path_level="${version_arr[2]}" + declare -i PATCH_LEVEL="${_path_level%%-*}" + + ## - Get current MySQL Distribution + ## - + echononl " Get current MySQL distribution .." + if [[ -z "$_version" ]]; then + echo_failed + fatal "No installed MySQL server or distribution found!" + elif [[ "$_version" =~ MariaDB ]]; then + MYSQL_CUR_DISTRIBUTION="MariaDB" + else + MYSQL_CUR_DISTRIBUTION="MySQL" + fi + echo_ok + echo "" + echo -e "\033[32m--\033[m" + echo "" + +else + # Try to detect local MySQL Installation + # + detect_mysql_version + + MAJOR_VERSION="$MYSQL_MAJOR_VERSION" + MINOR_VERSION="$MYSQL_MINOR_VERSION" + PATCH_LEVEL="$MYSQL_PATCH_LEVEL" + + if [[ "$MYSQL_CUR_DISTRIBUTION" = "MariaDB" ]] && ([[ $MAJOR_VERSION -gt 10 ]] \ + || ( [[ $MAJOR_VERSION -eq 10 ]] && [[ $MINOR_VERSION -gt 3 ]] )) ; then + if [[ -S "/tmp/mysql.sock" ]]; then + DATABASE_CREDENTIALS_ARGS="-u root -S /tmp/mysql.sock" + elif [[ -S "/run/mysqld/mysqld.sock" ]]; then + DATABASE_CREDENTIALS_ARGS="-u root -S /run/mysqld/mysqld.sock" + elif [[ -S "/var/run/mysqld/mysqld.sock" ]]; then + DATABASE_CREDENTIALS_ARGS="-u root -S /var/run/mysqld/mysqld.sock" + else + fatal "Parameter 'DATABASE_CREDENTIALS_ARGS' cannot be determined automated. + + Use configuration file "$conf_file" or commandline Parameter or set + thr mysql credentials." + fi + else + if $(${mysql_command} --login-path=local -e ";" > /dev/null 2>&1) ; then + DATABASE_CREDENTIALS_ARGS="--login-path=local" + elif [[ -f "/usr/local/mysql/sys-maint.cnf" ]] ; then + DATABASE_CREDENTIALS_ARGS="--defaults-file=/usr/local/mysql/sys-maint.cnf" + elif [[ -f "/etc/mysql/debian.cnf" ]] ; then + DATABASE_CREDENTIALS_ARGS="--defaults-file=/etc/mysql/debian.cnf" + else + fatal "Parameter 'DATABASE_CREDENTIALS_ARGS' cannot be determined automated. + + Use configuration file "$conf_file" to set + parameter manually." + fi + fi + +fi + + if ! $QUIET_MODE ; then echo "" echo "" @@ -703,6 +810,8 @@ if ! $QUIET_MODE ; then echo " MySQL Version................: ${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_LEVEL}" fi echo "" + echo " MySQL Command................: ${mysql_command}" + echo "" if [[ -n "$DATABASE_SERVER" ]] ; then echo " Database server..............: $DATABASE_SERVER" else @@ -754,11 +863,11 @@ fi echononl " Check connection to Database Server.." if [[ -n "$DATABASE_SERVER" ]] ; then - if ! $(mysql -h $DATABASE_SERVER $DATABASE_CREDENTIALS_ARGS -e ";" > /dev/null 2>&1) ; then + if ! $(${mysql_command} -h $DATABASE_SERVER $DATABASE_CREDENTIALS_ARGS -e ";" > /dev/null 2>&1) ; then fatal "Cannot connect to Database Server '$DATABASE_SERVER'!" fi else - if ! $(mysql $DATABASE_CREDENTIALS_ARGS -e ";" > /dev/null 2>&1) ; then + if ! $(${mysql_command} $DATABASE_CREDENTIALS_ARGS -e ";" > /dev/null 2>&1) ; then fatal "Cannot connect to Database Server!" fi fi @@ -766,11 +875,11 @@ echo_done echononl " Check connection to Database '$DATABASE_NAME'.." if [[ -n "$DATABASE_SERVER" ]] ; then - if ! $(mysql -h $DATABASE_SERVER $DATABASE_CREDENTIALS_ARGS $DATABASE_NAME -e ";" > /dev/null 2>&1) ; then + if ! $(${mysql_command} -h $DATABASE_SERVER $DATABASE_CREDENTIALS_ARGS $DATABASE_NAME -e ";" > /dev/null 2>&1) ; then fatal "Cannot connect to Database '$DATABASE_NAME'!" fi else - if ! $(mysql $DATABASE_CREDENTIALS_ARGS $DATABASE_NAME -e ";" > /dev/null 2>&1) ; then + if ! $(${mysql_command} $DATABASE_CREDENTIALS_ARGS $DATABASE_NAME -e ";" > /dev/null 2>&1) ; then fatal "Cannot connect to Database '$DATABASE_NAME'!" fi fi @@ -830,7 +939,7 @@ blank_line # - GET current (global) Autocommit value # - echononl " GET current (global) value \033[1mautocommit\033[m" -CUR_AUTOCOMMIT="$(mysql $DATABASE_CREDENTIALS_ARGS -N -s -e "SHOW GLOBAL VARIABLES LIKE 'autocommit'" | awk '{print$2}')" >> $log_file 2>&1 +CUR_AUTOCOMMIT="$(${mysql_command} $DATABASE_CREDENTIALS_ARGS -N -s -e "SHOW GLOBAL VARIABLES LIKE 'autocommit'" | awk '{print$2}')" >> $log_file 2>&1 if [[ $? -eq 0 ]];then echo_ok else @@ -841,7 +950,7 @@ fi # - GET current (global) value for 'foreign_key_checks' # - echononl " GET current (global) value \033[1mforeign_key_checks\033[m" -CUR_FOREIGN_KEY_CHECKS="$(mysql $DATABASE_CREDENTIALS_ARGS -N -s -e "SHOW GLOBAL VARIABLES LIKE 'foreign_key_checks'" | awk '{print$2}')" >> $log_file 2>&1 +CUR_FOREIGN_KEY_CHECKS="$(${mysql_command} $DATABASE_CREDENTIALS_ARGS -N -s -e "SHOW GLOBAL VARIABLES LIKE 'foreign_key_checks'" | awk '{print$2}')" >> $log_file 2>&1 if [[ $? -eq 0 ]];then echo_ok else @@ -852,7 +961,7 @@ fi # - GET current (global) value for 'unique_checks' # - echononl " GET current (global) value \033[1munique_checks\033[m" -CUR_UNIQUE_CHECKS="$(mysql $DATABASE_CREDENTIALS_ARGS -N -s -e "SHOW GLOBAL VARIABLES LIKE 'unique_checks'" | awk '{print$2}')" >> $log_file 2>&1 +CUR_UNIQUE_CHECKS="$(${mysql_command} $DATABASE_CREDENTIALS_ARGS -N -s -e "SHOW GLOBAL VARIABLES LIKE 'unique_checks'" | awk '{print$2}')" >> $log_file 2>&1 if [[ $? -eq 0 ]];then echo_ok else @@ -863,7 +972,7 @@ fi # - GET current (global) value for 'innodb_flush_log_at_trx_commit' # - echononl " GET current (global) value \033[1minnodb_flush_log_at_trx_commit\033[m" -CUR_INNODB_FLUSH_LOG_AT_TRX_COMMIT="$(mysql $DATABASE_CREDENTIALS_ARGS -N -s -e "SHOW GLOBAL VARIABLES LIKE 'innodb_flush_log_at_trx_commit'" | awk '{print$2}')" >> $log_file 2>&1 +CUR_INNODB_FLUSH_LOG_AT_TRX_COMMIT="$(${mysql_command} $DATABASE_CREDENTIALS_ARGS -N -s -e "SHOW GLOBAL VARIABLES LIKE 'innodb_flush_log_at_trx_commit'" | awk '{print$2}')" >> $log_file 2>&1 if [[ $? -eq 0 ]];then echo_ok else @@ -874,7 +983,7 @@ fi # - GET current (global) value for 'max_allowed_packet' # - echononl " GET current (global) value \033[1mmax_allowed_packet\033[m" -CUR_MAX_ALLOWED_PACKET="$(mysql $DATABASE_CREDENTIALS_ARGS -N -s -e "SHOW GLOBAL VARIABLES LIKE 'max_allowed_packet'" | awk '{print$2}')" >> $log_file 2>&1 +CUR_MAX_ALLOWED_PACKET="$(${mysql_command} $DATABASE_CREDENTIALS_ARGS -N -s -e "SHOW GLOBAL VARIABLES LIKE 'max_allowed_packet'" | awk '{print$2}')" >> $log_file 2>&1 if [[ $? -eq 0 ]];then echo_ok else @@ -885,7 +994,7 @@ fi blank_line echononl " Set Autocommit to OFF" -mysql $DATABASE_CREDENTIALS_ARGS -N -s -e "SET GLOBAL autocommit='OFF'" >> $log_file 2>&1 +${mysql_command} $DATABASE_CREDENTIALS_ARGS -N -s -e "SET GLOBAL autocommit='OFF'" >> $log_file 2>&1 if [[ $? -eq 0 ]];then echo_ok else @@ -894,7 +1003,7 @@ else fi echononl " Set foreign_key_checks to OFF" -mysql $DATABASE_CREDENTIALS_ARGS -N -s -e "SET GLOBAL foreign_key_checks='OFF'" >> $log_file 2>&1 +${mysql_command} $DATABASE_CREDENTIALS_ARGS -N -s -e "SET GLOBAL foreign_key_checks='OFF'" >> $log_file 2>&1 if [[ $? -eq 0 ]];then echo_ok else @@ -903,7 +1012,7 @@ else fi echononl " Set unique_checks to OFF" -mysql $DATABASE_CREDENTIALS_ARGS -N -s -e "SET GLOBAL unique_checks='OFF'" >> $log_file 2>&1 +${mysql_command} $DATABASE_CREDENTIALS_ARGS -N -s -e "SET GLOBAL unique_checks='OFF'" >> $log_file 2>&1 if [[ $? -eq 0 ]];then echo_ok else @@ -912,7 +1021,7 @@ else fi echononl " Set innodb_flush_log_at_trx_commit to 2" -mysql $DATABASE_CREDENTIALS_ARGS -N -s -e "SET GLOBAL innodb_flush_log_at_trx_commit=2" >> $log_file 2>&1 +${mysql_command} $DATABASE_CREDENTIALS_ARGS -N -s -e "SET GLOBAL innodb_flush_log_at_trx_commit=2" >> $log_file 2>&1 if [[ $? -eq 0 ]];then echo_ok else @@ -921,7 +1030,7 @@ else fi echononl " Set max_allowed_packet to 1G" -mysql $DATABASE_CREDENTIALS_ARGS -N -s -e "SET GLOBAL max_allowed_packet=1073741824" >> $log_file 2>&1 +${mysql_command} $DATABASE_CREDENTIALS_ARGS -N -s -e "SET GLOBAL max_allowed_packet=1073741824" >> $log_file 2>&1 if [[ $? -eq 0 ]];then echo_ok else @@ -942,9 +1051,9 @@ fi echononl " Restore Database '${DATABASE_NAME}'.." b_timestamp=$(date +"%s") if [[ -n "$DATABASE_SERVER" ]] ; then - mysql -h $DATABASE_SERVER $DATABASE_CREDENTIALS_ARGS $DATABASE_NAME < $DATABASE_DUMP_FILE > $log_file 2>&1 + ${mysql_command} -h $DATABASE_SERVER $DATABASE_CREDENTIALS_ARGS $DATABASE_NAME < $DATABASE_DUMP_FILE > $log_file 2>&1 else - mysql $DATABASE_CREDENTIALS_ARGS $DATABASE_NAME < $DATABASE_DUMP_FILE > $log_file 2>&1 + ${mysql_command} $DATABASE_CREDENTIALS_ARGS $DATABASE_NAME < $DATABASE_DUMP_FILE > $log_file 2>&1 fi retval=$? e_timestamp=$(date +"%s") @@ -972,7 +1081,7 @@ if ! $QUIET_MODE ; then fi echononl " Set Autocommit to $CUR_AUTOCOMMIT" -mysql $DATABASE_CREDENTIALS_ARGS -N -s -e "SET GLOBAL autocommit='$CUR_AUTOCOMMIT'" >> $log_file 2>&1 +${mysql_command} $DATABASE_CREDENTIALS_ARGS -N -s -e "SET GLOBAL autocommit='$CUR_AUTOCOMMIT'" >> $log_file 2>&1 if [[ $? -eq 0 ]];then echo_ok CUR_AUTOCOMMIT="" @@ -982,7 +1091,7 @@ else fi echononl " Set foreign_key_checks to $CUR_FOREIGN_KEY_CHECKS" -mysql $DATABASE_CREDENTIALS_ARGS -N -s -e "SET GLOBAL foreign_key_checks='$CUR_FOREIGN_KEY_CHECKS'" >> $log_file 2>&1 +${mysql_command} $DATABASE_CREDENTIALS_ARGS -N -s -e "SET GLOBAL foreign_key_checks='$CUR_FOREIGN_KEY_CHECKS'" >> $log_file 2>&1 if [[ $? -eq 0 ]];then echo_ok CUR_FOREIGN_KEY_CHECKS="" @@ -992,7 +1101,7 @@ else fi echononl " Set unique_checks to $CUR_UNIQUE_CHECKS" -mysql $DATABASE_CREDENTIALS_ARGS -N -s -e "SET GLOBAL unique_checks='$CUR_UNIQUE_CHECKS'" >> $log_file 2>&1 +${mysql_command} $DATABASE_CREDENTIALS_ARGS -N -s -e "SET GLOBAL unique_checks='$CUR_UNIQUE_CHECKS'" >> $log_file 2>&1 if [[ $? -eq 0 ]];then echo_ok CUR_UNIQUE_CHECKS="" @@ -1002,7 +1111,7 @@ else fi echononl " Set innodb_flush_log_at_trx_commit to $CUR_INNODB_FLUSH_LOG_AT_TRX_COMMIT" -mysql $DATABASE_CREDENTIALS_ARGS -N -s -e "SET GLOBAL innodb_flush_log_at_trx_commit=$CUR_INNODB_FLUSH_LOG_AT_TRX_COMMIT" >> $log_file 2>&1 +${mysql_command} $DATABASE_CREDENTIALS_ARGS -N -s -e "SET GLOBAL innodb_flush_log_at_trx_commit=$CUR_INNODB_FLUSH_LOG_AT_TRX_COMMIT" >> $log_file 2>&1 if [[ $? -eq 0 ]];then echo_ok CUR_INNODB_FLUSH_LOG_AT_TRX_COMMIT="" @@ -1012,7 +1121,7 @@ else fi echononl " Set max_allowed_packet to $CUR_MAX_ALLOWED_PACKET" -mysql $DATABASE_CREDENTIALS_ARGS -N -s -e "SET GLOBAL max_allowed_packet=$CUR_MAX_ALLOWED_PACKET" >> $log_file 2>&1 +${mysql_command} $DATABASE_CREDENTIALS_ARGS -N -s -e "SET GLOBAL max_allowed_packet=$CUR_MAX_ALLOWED_PACKET" >> $log_file 2>&1 if [[ $? -eq 0 ]];then echo_ok CUR_MAX_ALLOWED_PACKET=""