Skip to content

Connect to a MySQL database

Maksym Zaporozhets edited this page Jan 8, 2024 · 3 revisions

docker:mysql:connect

Description

Connect to MySQL database with the MySQL client from the given container.

Usage

Simple usage:

```shell
php bin/dockerizer docker:mysql:connect -c <container>

Advanced usage with aliases:

# Export a global variable containing the path to your projects root directory
export DOCKERIZER_PROJECTS_ROOT_DIR=${HOME}/misc/apps/
# Alias to run Dockerizer from any directory
alias DOCKERIZER='php -d xdebug.start_with_request=trigger ${DOCKERIZER_PROJECTS_ROOT_DIR}dockerizer_for_php/bin/dockerizer'
# Run `CONNECT -e` to connect to a MySQL server via the MySQL client shipped within a container.
# You should be in the directory containing `docker-compose.yaml` file.
alias CONNECT='DOCKERIZER docker:mysql:connect -c $(DOCKERIZER composition:get-container-name mysql)'

Command options

  • -c (--container, required): Container name or ID.
  • -e (--exec, flag): Connect instead of returning a connection string.

Required environment variables

Inside a Docker container: MYSQL_USER/MYSQL_PASSWORD/MYSQL_DATABASE or respective MariaDB environment variables.

Clone this wiki locally