Home >Database >Mysql Tutorial >How to Connect MySQL Workbench to a Dockerized MySQL Instance?

How to Connect MySQL Workbench to a Dockerized MySQL Instance?

Patricia Arquette
Patricia ArquetteOriginal
2024-11-24 04:04:14438browse

How to Connect MySQL Workbench to a Dockerized MySQL Instance?

Overcoming MySQL Connectivity Issues with Docker and MySQL Workbench

Running MySQL within a Docker container can sometimes present connectivity challenges when accessing it from a local MySQL Workbench. This article delves into the solution to this problem.

Understanding the Connection Barrier

By default, MySQL imposes connection restrictions, limiting access to localhost connections only. This prevents external connections, including those from MySQL Workbench running on the host machine.

Allowing Root Access from All Hosts

To enable root access from all hosts:

  1. Start the MySQL Container:

    docker run -p 3306:3306 --name=mysql57 -d mysql/mysql-server:5.7
  2. Get the Default Password:

    docker logs mysql57 2>&1 | grep GENERATED
  3. Connect to MySQL:

    docker exec -it mysql57 mysql -uroot -p
  4. Alter User Settings:

    update mysql.user set host = '%' where user='root';
  5. Restart the Container:

    docker restart mysql57

Connecting from MySQL Workbench

Now, you can connect to MySQL from MySQL Workbench using the following parameters:

host: `0.0.0.0` 
port: `3306`

The above is the detailed content of How to Connect MySQL Workbench to a Dockerized MySQL Instance?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn