Home > Database > Mysql Tutorial > How to Connect MySQL Workbench to a MySQL Server in Docker?

How to Connect MySQL Workbench to a MySQL Server in Docker?

Susan Sarandon
Release: 2024-11-22 10:37:12
Original
907 people have browsed it

How to Connect MySQL Workbench to a MySQL Server in Docker?

Connecting to a MySQL Server Running in Docker using MySQL Workbench

Introduction:
Accessing MySQL databases within Docker containers can be a common requirement. However, connecting to these databases from external tools such as MySQL Workbench requires some configuration.

Solution:
To establish a connection from MySQL Workbench to a MySQL server running inside a Docker container, follow these steps:

  1. Configure MySQL Server:

    • Start a MySQL image with the required port mappings (e.g., docker run -p 3306:3306 mysql/mysql-server:5.7).
    • Log into the container using docker exec -it mysql57 mysql -uroot -p and update the MySQL user's host to % to allow connections from any IP address (e.g., update mysql.user set host = '%' where user='root';).
  2. Workbench Connection:

    • Open MySQL Workbench.
    • Click "New Connection" and enter the following:

      • Host: 0.0.0.0
      • Port: 3306
      • Username: root
      • Password: (obtained from Docker logs or set during MySQL setup)
  3. Connect and Use:

    • Click "Test Connection" to verify the connection.
    • Once successful, you can manage and interact with the MySQL database within the container from MySQL Workbench.

Verification:
Running select host, user from mysql.user; will show the updated host value for the MySQL user, confirming that connections are now allowed from any host.

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

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template