From 52b57aafea33bb03b7b25bc0f30eb018468728d8 Mon Sep 17 00:00:00 2001 From: Christoph Date: Sat, 2 Nov 2019 02:37:34 +0100 Subject: [PATCH] create_database.sh: support mariadb 10.4 --- create_database.sh | 54 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/create_database.sh b/create_database.sh index 6f19020..78d883a 100755 --- a/create_database.sh +++ b/create_database.sh @@ -666,6 +666,60 @@ if [[ "$MYSQL_CUR_DISTRIBUTION" = "MySQL" ]] && ([[ $MAJOR_VERSION -gt 8 ]] \ fi +elif [[ "$MYSQL_CUR_DISTRIBUTION" = "MariaDB" ]] && ([[ $MAJOR_VERSION -gt 10 ]] \ + || ( [[ $MAJOR_VERSION -eq 10 ]] && [[ $MINOR_VERSION -gt 3 ]] )) ; then + + echononl " Create database user '$DATABASE_USER'" + 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 " Grant permissions to access and use the MySQL server to user '$DATABASE_USER'" + mysql $MYSQL_CREDENTIAL_ARGS -N -s -e \ + "GRANT USAGE 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 + + echononl " Grant all privileges to a 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 " Allow access to user '$DATABASE_USER' on Database '$DATABASE_NAME' from '$_ip'" + mysql $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 + error "$(cat $tmp_log_file)" + else + echo_ok + fi + + done + + fi + else echononl " Grant usage to user '$DATABASE_USER' (Creates User..)"