From bace345da4c6ff4f89e6cda0f916d8789ea5dba8 Mon Sep 17 00:00:00 2001 From: Kevin Morris Date: Sun, 8 Aug 2021 18:32:35 -0700 Subject: [PATCH] Docker: support both '%' and 'localhost' in mariadb This is needed to be able to reach the mysql service from other hosts or through localhost. Handling both cases here means that we can support both localhost access and host access. Signed-off-by: Kevin Morris --- docker/mariadb-entrypoint.sh | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/docker/mariadb-entrypoint.sh b/docker/mariadb-entrypoint.sh index e38900c8..945a4b82 100755 --- a/docker/mariadb-entrypoint.sh +++ b/docker/mariadb-entrypoint.sh @@ -18,15 +18,19 @@ DATABASE="aurweb" # Persistent database for fastapi/php-fpm. TEST_DB="aurweb_test" # Test database (ephemereal). echo "Taking care of primary database '${DATABASE}'..." -mysql -u root -e "CREATE USER IF NOT EXISTS 'aur'@'$DB_HOST' IDENTIFIED BY 'aur';" +mysql -u root -e "CREATE USER IF NOT EXISTS 'aur'@'localhost' IDENTIFIED BY 'aur';" +mysql -u root -e "CREATE USER IF NOT EXISTS 'aur'@'%' IDENTIFIED BY 'aur';" mysql -u root -e "CREATE DATABASE IF NOT EXISTS $DATABASE;" -mysql -u root -e "GRANT ALL ON ${DATABASE}.* TO 'aur'@'$DB_HOST';" +mysql -u root -e "GRANT ALL ON ${DATABASE}.* TO 'aur'@'localhost';" +mysql -u root -e "GRANT ALL ON ${DATABASE}.* TO 'aur'@'%';" # Drop and create our test database. echo "Dropping test database '$TEST_DB'..." mysql -u root -e "DROP DATABASE IF EXISTS $TEST_DB;" mysql -u root -e "CREATE DATABASE $TEST_DB;" -mysql -u root -e "GRANT ALL ON ${TEST_DB}.* TO 'aur'@'$DB_HOST';" +mysql -u root -e "GRANT ALL ON ${TEST_DB}.* TO 'aur'@'localhost';" +mysql -u root -e "GRANT ALL ON ${TEST_DB}.* TO 'aur'@'%';" + echo "Created new '$TEST_DB'!" mysqladmin -uroot shutdown