Skip to content

Instantly share code, notes, and snippets.

@ezarko
Last active May 20, 2016 16:30
Show Gist options
  • Save ezarko/6ae06f08fbf9c7632b64bdab114c30c4 to your computer and use it in GitHub Desktop.
Save ezarko/6ae06f08fbf9c7632b64bdab114c30c4 to your computer and use it in GitHub Desktop.
Useful bash function for interacting with a mysql database in a mariadb docker container.
# mysql <container> [...]
function mysql {
docker run -it --link $1:mysql --rm mariadb sh -c "exec mysql -h\"\$MYSQL_PORT_3306_TCP_ADDR\" -P\"\$MYSQL_PORT_3306_TCP_PORT\" -uroot -p\"\$MYSQL_ENV_MYSQL_ROOT_PASSWORD\" ${@:2}"
}
# mysqladmin <container> [...]
function mysqladmin {
docker run -it --link $1:mysql --rm mariadb sh -c "exec mysqladmin -h\"\$MYSQL_PORT_3306_TCP_ADDR\" -P\"\$MYSQL_PORT_3306_TCP_PORT\" -uroot -p\"\$MYSQL_ENV_MYSQL_ROOT_PASSWORD\" ${@:2}"
}
# mysqldump <container> [...]
function mysqldump {
docker run -it --link $1:mysql --rm mariadb sh -c "exec mysqldump -h\"\$MYSQL_PORT_3306_TCP_ADDR\" -P\"\$MYSQL_PORT_3306_TCP_PORT\" -uroot -p\"\$MYSQL_ENV_MYSQL_ROOT_PASSWORD\" ${@:2}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment