---
title: "How to connect to MySQL in a docker container from the host?"  
description: "How to connect to MySQL in a docker container from the host?"  
author: "Utpal Vishwas"  
published: 2023-08-21  
updated: 2023-08-23  
canonical: https://www.mindstick.com/forum/159612/how-to-connect-to-mysql-in-a-docker-container-from-the-host  
category: "mysql"  
tags: ["mysql", "hosting", "docker container"]  
reading_time: 2 minutes  

---

# How to connect to MySQL in a docker container from the host?

How to [connect](https://www.mindstick.com/articles/12810/how-to-connect-tablet-to-external-monitor-or-flat-screen-tv-using-computer-adapters) to [MySQL](https://www.mindstick.com/articles/12156/what-is-mysql) in a [docker](https://www.mindstick.com/forum/161003/what-is-docker) [container](https://www.mindstick.com/forum/159610/how-to-connect-a-windows-container-to-a-service-running-on-localhost) from the [host](https://yourviews.mindstick.com/view/85456/foreign-direct-investment-fdi-and-its-impacts-on-host-countries)?

## Replies

### Reply by Aryan Kumar

There are a few ways to connect to MySQL in a Docker container from the host.

**Using the** `docker exec` **command:** The `docker exec` command allows you to run a command inside a Docker container. To connect to MySQL in a container using the `docker exec` command, you need to specify the container name or ID and the command you want to run. For example, to connect to MySQL in the container named `mycontainer` and run the `mysql` command, you would run the following command:

```plaintext
docker exec mycontainer mysql
```

This will open a MySQL shell in the container. You can then use the MySQL shell to connect to the database.

**Using a third-party tool:** There are a number of third-party tools that can help you connect to MySQL in Docker containers. Some of these tools include: * MySQL Workbench: https://dev.mysql.com/downloads/workbench/: A graphical tool for managing MySQL databases. * Sequel Pro: https://www.sequelpro.com/: Another graphical tool for managing MySQL databases. * MySQL Shell: https://dev.mysql.com/downloads/shell/: A command-line tool for managing MySQL databases.

The best way to connect to MySQL in a Docker container from the host depends on the specific situation. If you are comfortable using the command line, then the `docker exec` command is the easiest way to do it. If you want to use a graphical tool, then you can use a third-party tool like MySQL Workbench or Sequel Pro.

Here are the steps on how to connect to MySQL in a Docker container using the `docker exec` command:

1. Find the container ID of the container that has MySQL running.
2. Run the `docker exec` command to connect to the container and run the `mysql` command.
3. Enter the password for the MySQL user.
4. You will be connected to the MySQL database.


---

Original Source: https://www.mindstick.com/forum/159612/how-to-connect-to-mysql-in-a-docker-container-from-the-host

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
