Skip to content

Instantly share code, notes, and snippets.

@luksi1
Created May 21, 2018 11:28
Show Gist options
  • Save luksi1/e60b4818d17554cfe5133ce8b16d6307 to your computer and use it in GitHub Desktop.
Save luksi1/e60b4818d17554cfe5133ce8b16d6307 to your computer and use it in GitHub Desktop.
MySQL Docker commands
# Get MySQL CLI
docker exec -it <CONTAINER> sh -c 'mysql -u${MYSQL_USER} --password=${MYSQL_PASSWORD}'
# Run SQL script
cp my.sql /path/to/mysql/volume
docker exec <CONTAINER> sh -c 'mysql -u${MYSQL_USER} --password=${MYSQL_PASSWORD} $MYSQL_DATABASE < /var/lib/mysql/my.sql'
# Backup MySQL database
docker exec <CONTAINER> sh -c 'exec mysqldump -u${MYSQL_USER} --password=${MYSQL_PASSWORD} $MYSQL_DATABASE' > my.backup.sql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment