forked from Ninjaclasher/dmoj-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Parse vars before being passed into mariadb
- Loading branch information
1 parent
d8328bd
commit 94b6bb8
Showing
1 changed file
with
17 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,19 @@ | ||
sudo mariadb | ||
CREATE DATABASE IF NOT EXISTS "$MYSQL_DATABASE" DEFAULT CHARACTER SET utf8mb4 DEFAULT COLLATE utf8mb4_general_ci; | ||
GRANT ALL PRIVILEGES ON "$MYSQL_DATABASE".* TO "$MYSQL_USER"@'localhost' IDENTIFIED BY "$MYSQL_PASSWORD"; | ||
# shellcheck disable=SC2035 # this is in a mariadb shell so it wont glob | ||
GRANT RELOAD, PROCESS ON *.* TO "$MYSQL_USER"@'%'; | ||
#!/bin/bash | ||
|
||
# Load environment variables from environment/mysql.env | ||
set -a | ||
source environment/mysql.env | ||
source environment/mysql-admin.env | ||
set +a | ||
|
||
# Create SQL command with expanded variables (note the backticks for command substitution) | ||
SQL=" | ||
CREATE DATABASE IF NOT EXISTS ${MYSQL_DATABASE} DEFAULT CHARACTER SET utf8mb4 DEFAULT COLLATE utf8mb4_general_ci; | ||
GRANT ALL PRIVILEGES ON ${MYSQL_DATABASE}.* TO '${MYSQL_USER}'@'localhost' IDENTIFIED BY '${MYSQL_PASSWORD}'; | ||
GRANT RELOAD, PROCESS ON *.* TO '${MYSQL_USER}'@'%'; | ||
FLUSH PRIVILEGES; | ||
exit | ||
mariadb-tzinfo-to-sql /usr/share/zoneinfo | sudo mariadb -u root mysql | ||
" | ||
|
||
# Execute SQL command in MariaDB | ||
mariadb -u "${MYSQL_USER}" -p"${MYSQL_PASSWORD}" -e "$SQL" |