create_database.sh: add support for MySQL version 8.0.x

This commit is contained in:
Christoph 2018-08-03 23:49:05 +00:00
parent bbed466b7f
commit dafc793007

View File

@ -390,6 +390,34 @@ if ! $QUIET_MODE ; then
echo ""
fi
# - Get MySQL Version
# -
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
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%%-*}"
if ! $QUIET_MODE ; then
if [[ $MAJOR_VERSION -gt 8 ]] \
|| ( [[ $MAJOR_VERSION -eq 8 ]] && [[ $MINOR_VERSION -gt 0 ]] ) \
|| ( [[ $MAJOR_VERSION -eq 8 ]] && [[ $MINOR_VERSION -eq 0 ]] && [[ $PATCH_LEVEL -ge 3 ]] ) ; then
info "Using (old) Password Plugin 'mysql_native_password'"
else
echo ""
fi
fi
# - Test if Database already exists
# -
@ -408,15 +436,44 @@ else
echo_ok
fi
echononl " Grant full access to user '$DATABASE_USER' on Database '$DATABASE_NAME'"
mysql $MYSQL_CREDENTIAL_ARGS -N -s -e \
"GRANT ALL ON ${DATABASE_NAME}.* TO '$DATABASE_USER'@'localhost' IDENTIFIED BY '$DATABASE_PASSWD'" > $tmp_log_file 2>&1
if [[ $? -ne 0 ]] ; then
echo_failed
error "$(cat $tmp_log_file)"
if [[ $MAJOR_VERSION -gt 8 ]] \
|| ( [[ $MAJOR_VERSION -eq 8 ]] && [[ $MINOR_VERSION -gt 0 ]] ) \
|| ( [[ $MAJOR_VERSION -eq 8 ]] && [[ $MINOR_VERSION -eq 0 ]] && [[ $PATCH_LEVEL -ge 3 ]] ) ; then
echononl " Create database user '$DATABASE_USER'"
mysql $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
echo_failed
error "$(cat $tmp_log_file)"
else
echo_ok
fi
echononl " Grant full access to user '$DATABASE_USER' on Database '$DATABASE_NAME'"
mysql $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
error "$(cat $tmp_log_file)"
else
echo_ok
fi
else
echo_ok
fi
echononl " Grant full access to user '$DATABASE_USER' on Database '$DATABASE_NAME'"
mysql $MYSQL_CREDENTIAL_ARGS -N -s -e \
"GRANT ALL ON ${DATABASE_NAME}.* TO '$DATABASE_USER'@'localhost' IDENTIFIED BY '$DATABASE_PASSWD'" > $tmp_log_file 2>&1
if [[ $? -ne 0 ]] ; then
echo_failed
error "$(cat $tmp_log_file)"
else
echo_ok
fi
fi # if [[ $MAJOR_VERSION -ge 8 ]]
echononl " Also grant 'Super_priv' privilege to '$DATABASE_USER' on Database '$DATABASE_NAME'"
mysql $MYSQL_CREDENTIAL_ARGS -N -s -e \