Properly rebuild_mysql_database password for MariaDB > 10.4

This commit is contained in:
myvesta 2021-11-07 14:26:16 +01:00 committed by GitHub
parent 39c9ebc2a7
commit 4bb53ff28f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -568,21 +568,30 @@ rebuild_mysql_database() {
fi
else
# mariadb
if [ "$(echo $mysql_ver |cut -d '.' -f1)" -eq 5 ]; then
mysql_ver_sub=$(echo $mysql_ver |cut -d '.' -f1)
mysql_ver_sub_sub=$(echo $mysql_ver |cut -d '.' -f2)
if [ "$mysql_ver_sub" -eq 5 ]; then
# mariadb = 5
mysql_query "CREATE USER \`$DBUSER\`" > /dev/null
mysql_query "CREATE USER \`$DBUSER\`@localhost" > /dev/null
query="UPDATE mysql.user SET Password='$MD5' WHERE User='$DBUSER'"
else
# mariadb = 10
mysql_query "CREATE USER IF NOT EXISTS \`$DBUSER\`" > /dev/null
mysql_query "CREATE USER IF NOT EXISTS \`$DBUSER\`@localhost" > /dev/null
query="UPDATE mysql.user SET Password='$MD5' WHERE User='$DBUSER'"
if [ "$mysql_ver_sub_sub" -ge 4 ]; then
query="SET PASSWORD FOR '$DBUSER'@'%' = '$MD5';"
query2="SET PASSWORD FOR '$DBUSER'@'localhost' = '$MD5';"
fi
fi
# mariadb any version
query="UPDATE mysql.user SET Password='$MD5' WHERE User='$DBUSER'"
fi
mysql_query "GRANT ALL ON \`$DB\`.* TO \`$DBUSER\`@\`%\`" >/dev/null
mysql_query "GRANT ALL ON \`$DB\`.* TO \`$DBUSER\`@localhost" >/dev/null
mysql_query "$query" >/dev/null
if [ ! -z "$query2" ]; then
mysql_query "$query2" >/dev/null
fi
mysql_query "FLUSH PRIVILEGES" >/dev/null
}