From a1844d8c880e24670ed80e70ef79b8a131e55f19 Mon Sep 17 00:00:00 2001 From: Volodymyr Kolesnykov Date: Wed, 14 Feb 2024 04:05:21 +0200 Subject: [PATCH] fix(dev-tools): grant privileges to MySQL users properly --- dev-tools/setup.sh | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/dev-tools/setup.sh b/dev-tools/setup.sh index b048e1cf..e365bea6 100755 --- a/dev-tools/setup.sh +++ b/dev-tools/setup.sh @@ -112,28 +112,14 @@ if ! mysqladmin ping -h "${db_host}" --silent; then exit 1; fi -echo "Checking for database connectivity..." -if ! mysql -h "$db_host" -u wordpress -pwordpress wordpress -e "SELECT 'testing_db'" >/dev/null 2>&1; then - echo "No WordPress database exists, provisioning..." - { - echo "CREATE USER IF NOT EXISTS 'wordpress'@'localhost' IDENTIFIED BY 'wordpress';" - echo "CREATE USER IF NOT EXISTS 'wordpress'@'%' IDENTIFIED BY 'wordpress';" - echo "GRANT ALL ON *.* TO 'wordpress'@'localhost';" - echo "GRANT ALL ON *.* TO 'wordpress'@'%';" - echo "GRANT SET_ANY_DEFINER ON *.* TO 'wordpress'@'localhost';" - echo "GRANT SET_ANY_DEFINER ON *.* TO 'wordpress'@'%';" - echo "CREATE DATABASE IF NOT EXISTS wordpress;" - } | mysql -h "$db_host" -u "$db_admin_user" -fi - -if ! mysql -h "${db_host}" -unetapp -pwordpress wordpress -e "SELECT 'testing_db'" >/dev/null 2>&1; then - { - echo "CREATE USER IF NOT EXISTS 'netapp'@'localhost' IDENTIFIED BY 'wordpress';" - echo "CREATE USER IF NOT EXISTS 'netapp'@'%' IDENTIFIED BY 'wordpress';" - echo "GRANT ALL ON *.* TO 'netapp'@'localhost';" - echo "GRANT ALL ON *.* TO 'netapp'@'%';" - } | mysql -h "${db_host}" -u "${db_admin_user}" -fi +{ + echo "CREATE USER IF NOT EXISTS 'wordpress'@'%' IDENTIFIED BY 'wordpress';" + echo "CREATE USER IF NOT EXISTS 'netapp'@'%' IDENTIFIED BY 'wordpress';" + echo "GRANT ALL ON wordpress.* TO 'wordpress'@'%';" + echo "GRANT ALL ON wordpress.* TO 'netapp'@'%';" + echo "GRANT SET_ANY_DEFINER ON *.* TO 'wordpress'@'%';" + echo "CREATE DATABASE IF NOT EXISTS wordpress;" +} | mysql -h "$db_host" -u "$db_admin_user" echo "Copying dev-env-plugin.php to mu-plugins" cp /dev-tools/dev-env-plugin.php /wp/wp-content/mu-plugins/