How to execute MySQL command from the host to container running MySQL server?

前端 未结 9 1829
春和景丽
春和景丽 2021-01-30 06:31

I have followed the instruction in https://registry.hub.docker.com/_/mysql/ to pull an image and running a container in which it runs a MySQL server.

The container is run

9条回答
  •  悲&欢浪女
    2021-01-30 07:27

    To connect to the MySQL database using MySQL command line client.

    1. I connect to the bash into the running MySQL container:

      $ docker exec -t -i container_mysql_name /bin/bash

      -i is the shortcut for --interactive option. This options is used for keep STDIN open even if not attached

      -t is the shortcut for --tty option, used to allocate a pseudo-TTY

    2. I run MySQL client from bash MySQL container:

      $ mysql -uroot -proot

      -u is shortcut for --user=name option, used to define user for login if not current user.

      -p is shortcut for -password[=name] option, used to define password to use when connecting to server. If password is not given it's asked from the tty.

    3. Disco!

提交回复
热议问题