create_database.sh: add support for MariaDB
This commit is contained in:
parent
19c2e2f5bc
commit
5221328f91
@ -430,6 +430,21 @@ 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"
|
||||
elif [[ "$(basename "$(realpath "/usr/local/mysql")")" =~ percona- ]]; then
|
||||
MYSQL_CUR_DISTRIBUTION="Percona"
|
||||
elif [[ "$(basename "$(realpath "/usr/local/mysql")")" =~ mysql- ]]; then
|
||||
MYSQL_CUR_DISTRIBUTION="MySQL"
|
||||
fi
|
||||
echo_ok
|
||||
|
||||
|
||||
|
||||
# - Test if Database already exists
|
||||
@ -449,7 +464,57 @@ else
|
||||
echo_ok
|
||||
fi
|
||||
|
||||
if [[ $MAJOR_VERSION -gt 8 ]] \
|
||||
if [[ "$MYSQL_CUR_DISTRIBUTION" = "MariaDB" ]] ; then
|
||||
|
||||
echononl " Grant usage to user '$DATABASE_USER' (Creates User..)"
|
||||
mysql $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
|
||||
error "$(cat $tmp_log_file)"
|
||||
else
|
||||
echo_ok
|
||||
fi
|
||||
|
||||
echononl " Grant all privileges to user '$DATABASE_USER' on Database '$DATABASE_NAME'"
|
||||
mysql $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
|
||||
error "$(cat $tmp_log_file)"
|
||||
else
|
||||
echo_ok
|
||||
fi
|
||||
|
||||
if $ACCESS_FROM_OUTSIDE ; then
|
||||
|
||||
for _ip in $IP_ADDRESSES ; do
|
||||
|
||||
echononl " Grant usage to user '$DATABASE_USER' access from ${_ip}"
|
||||
mysql $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
|
||||
error "$(cat $tmp_log_file)"
|
||||
else
|
||||
echo_ok
|
||||
fi
|
||||
|
||||
echononl " Grant all privileges to user '$DATABASE_USER' on Database '$DATABASE_NAME' from $_ip"
|
||||
mysql $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
|
||||
error "$(cat $tmp_log_file)"
|
||||
else
|
||||
echo_ok
|
||||
fi
|
||||
|
||||
done
|
||||
|
||||
fi
|
||||
|
||||
elif [[ $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
|
||||
|
||||
@ -480,9 +545,9 @@ if [[ $MAJOR_VERSION -gt 8 ]] \
|
||||
|
||||
for _ip in $IP_ADDRESSES ; do
|
||||
|
||||
echononl " Create database user '$DATABASE_USER' access from 192.168.3.122 "
|
||||
echononl " Create database user '$DATABASE_USER' access from '$_ip' "
|
||||
mysql $MYSQL_CREDENTIAL_ARGS -N -s -e \
|
||||
"CREATE USER '$DATABASE_USER'@'192.168.3.122' IDENTIFIED WITH mysql_native_password BY '$DATABASE_PASSWD'" \
|
||||
"CREATE USER '$DATABASE_USER'@'$_ip' IDENTIFIED WITH mysql_native_password BY '$DATABASE_PASSWD'" \
|
||||
> $tmp_log_file 2>&1
|
||||
if [[ $? -ne 0 ]] ; then
|
||||
echo_failed
|
||||
@ -495,40 +560,6 @@ if [[ $MAJOR_VERSION -gt 8 ]] \
|
||||
fi
|
||||
|
||||
|
||||
# # - Use default (password plugin) - at time: caching_sha2_password
|
||||
# # -
|
||||
# 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 default Password Plugin"
|
||||
# else
|
||||
# echo ""
|
||||
# fi
|
||||
# fi
|
||||
#
|
||||
# echononl " Create database user '$DATABASE_USER'@'localhost'.."
|
||||
# mysql $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)"
|
||||
# else
|
||||
# echo_ok
|
||||
# fi
|
||||
#
|
||||
# echononl " Create database user '$DATABASE_USER'@'192.168.3.122'.."
|
||||
# mysql $MYSQL_CREDENTIAL_ARGS -N -s -e \
|
||||
# "CREATE USER '$DATABASE_USER'@'192.168.3.122' IDENTIFIED 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
|
||||
@ -543,9 +574,9 @@ if [[ $MAJOR_VERSION -gt 8 ]] \
|
||||
|
||||
for _ip in $IP_ADDRESSES ; do
|
||||
|
||||
echononl " Grant full access to user '$DATABASE_USER' on Database '$DATABASE_NAME' from '192.168.3.122'"
|
||||
echononl " Grant full access to user '$DATABASE_USER' on Database '$DATABASE_NAME' from '$_ip'"
|
||||
mysql $MYSQL_CREDENTIAL_ARGS -N -s -e \
|
||||
"GRANT ALL ON ${DATABASE_NAME}.* TO '$DATABASE_USER'@'192.168.3.122'" > $tmp_log_file 2>&1
|
||||
"GRANT ALL ON ${DATABASE_NAME}.* TO '$DATABASE_USER'@'$_ip'" > $tmp_log_file 2>&1
|
||||
if [[ $? -ne 0 ]] ; then
|
||||
echo_failed
|
||||
error "$(cat $tmp_log_file)"
|
||||
@ -579,17 +610,36 @@ else
|
||||
echo_ok
|
||||
fi
|
||||
|
||||
fi # if [[ $MAJOR_VERSION -ge 8 ]]
|
||||
if $ACCESS_FROM_OUTSIDE ; then
|
||||
|
||||
for _ip in $IP_ADDRESSES ; do
|
||||
|
||||
echononl " Grant usage to user '$DATABASE_USER' access from ${_ip}"
|
||||
mysql $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
|
||||
error "$(cat $tmp_log_file)"
|
||||
else
|
||||
echo_ok
|
||||
fi
|
||||
|
||||
echononl " Grant all privileges to user '$DATABASE_USER' on Database '$DATABASE_NAME' from $_ip"
|
||||
mysql $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
|
||||
error "$(cat $tmp_log_file)"
|
||||
else
|
||||
echo_ok
|
||||
fi
|
||||
|
||||
done
|
||||
|
||||
fi
|
||||
|
||||
fi # if [[ $MYSQL_CUR_DISTRIBUTION -ge 8 ]]
|
||||
|
||||
#echononl " Also grant 'Super_priv' privilege to '$DATABASE_USER' on Database '$DATABASE_NAME'"
|
||||
#mysql $MYSQL_CREDENTIAL_ARGS -N -s -e \
|
||||
# "USE mysql; UPDATE user SET Super_priv = 'Y' WHERE User = '$DATABASE_USER'" > $tmp_log_file 2>&1
|
||||
#if [[ $? -ne 0 ]] ; then
|
||||
# echo_failed
|
||||
# error "$(cat $tmp_log_file)"
|
||||
#else
|
||||
# echo_ok
|
||||
#fi
|
||||
|
||||
echononl " Flush Privileges.."
|
||||
mysql $MYSQL_CREDENTIAL_ARGS -N -s -e "FLUSH PRIVILEGES" > $tmp_log_file 2>&1
|
||||
|
Loading…
Reference in New Issue
Block a user