Created
September 9, 2017 16:48
-
-
Save trnila/ae5b43341b75a08cbbea7eceb043fbef to your computer and use it in GitHub Desktop.
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/sh | |
container=$1 | |
pass=$2 | |
if [ -z "$container" ] || [ -z "$pass" ]; then | |
echo "usage: $0 container newRootPassword" | |
exit | |
fi | |
mysql_image=$(docker inspect $container --format "{{ .Config.Image }}") | |
mount=$(docker inspect $container --format "{{ .Mounts }}" | grep /var/lib/mysql | awk '{print $2}') | |
docker stop $container | |
docker run -d --rm --name mysql-recover -v $mount:/var/lib/mysql $mysql_image --skip-grant-tables | |
sleep 5 | |
docker exec -it mysql-recover mysql -u root -e "FLUSH PRIVILEGES;ALTER USER 'root'@'localhost' IDENTIFIED BY '$pass';" | |
docker stop mysql-recover | |
docker start $container |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment