Skip to content

Instantly share code, notes, and snippets.

@soulseekah
Created January 5, 2024 10:51
Show Gist options
  • Save soulseekah/6345fea0bd54af239028cd00d049646c to your computer and use it in GitHub Desktop.
Save soulseekah/6345fea0bd54af239028cd00d049646c to your computer and use it in GitHub Desktop.
Reset root password script for mariadb docker image (docker compose)
#!/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
@soulseekah
Copy link
Author

Use ./maria-unlock.sh newpassword

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment