Created
January 5, 2024 10:51
-
-
Save soulseekah/6345fea0bd54af239028cd00d049646c to your computer and use it in GitHub Desktop.
Reset root password script for mariadb docker image (docker compose)
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
#!/bin/bash | |
COMMAND="echo \"*** Starting unlock procedure...\";" | |
COMMAND="$COMMAND /usr/sbin/mariadbd --verbose --user=root --skip-grant-tables 2>/tmp/mariadbd.err &" | |
COMMAND="$COMMAND echo -n \"*** Waiting for database connection\";" | |
COMMAND="$COMMAND until mariadb -e 'SELECT 1' 2>/tmp/mariadb.err 1>/tmp/mariadb.err; do echo -n '.'; done; echo;" | |
COMMAND="$COMMAND echo '*** Connected! Setting root password to: $1';" | |
COMMAND="$COMMAND mariadb -e \"FLUSH PRIVILEGES; ALTER USER 'root'@'localhost' IDENTIFIED BY '$1'; SHUTDOWN;\" &" | |
# Uncomment this line to grab debug output if things aren't working | |
# COMMAND="$COMMAND echo; echo '*** Debug log:'; echo; cat /tmp/mariadb*.err;" | |
COMMAND="$COMMAND echo -n \"*** Waiting for database shutdown\";" | |
COMMAND="$COMMAND while mariadb -uroot -p'$1' -e 'SELECT 1' 2>/tmp/mariadb.err 1>/tmp/mariadb.err; do echo -n '.'; done; echo;" | |
COMMAND="$COMMAND echo \"*** Hope this helped ;)\";" | |
docker compose down | |
docker compose run --rm db bash -c "$COMMAND" | |
docker compose up -d |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use
./maria-unlock.sh newpassword