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 <kevr@0cost.org>
This commit is contained in:
Kevin Morris 2021-08-08 18:32:35 -07:00
parent 04d1c81d3d
commit bace345da4
No known key found for this signature in database
GPG key ID: F7E46DED420788F3

View file

@ -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