Connecting to Docker MySQL using MySQL Workbench

Connecting to Docker MySQL using MySQL Workbench

July 19, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Connecting to Docker MySQL using MySQL Workbench

Connecting MySQL Workbench to a Docker Container

As a senior developer, I understand the frustration that arises when trying to connect to a database on a Docker container using MySQL Workbench. In this post, I’ll guide you through the process of establishing a connection correctly.

Understanding Your Docker Environment

First, let’s break down your docker ps output:

  • 25da671f766d: This is your Nginx container.
  • f1f7fb0e7174: The PHP-FPM container for running Magento 2.
  • 69388c2ce5c7: Your Percona MySQL server running in a Docker container on port 3306.

Connecting to the MySQL Server

For the SSH settings, you don’t need them when connecting directly to your MySQL server inside your Docker network. Here’s how to configure MySQL Workbench:

  1. SSH Hostname: Leave this field blank.
  2. SSH Username: Also leave this blank.

Now focus on the MySQL connection details:

  • MySQL Hostname: This should be 0.0.0.0. In your case, CLIENTaws_db_1 is accessible at this address within your Docker network.
  • MySQL Server port: The default for Percona is 3306, so you’re correct here.

Connecting to the Database

For the database details:

  • Database name: Leave as magento.
  • User Name and Password: Both should be magento. Make sure they match exactly; leading or trailing spaces can cause issues.

Troubleshooting Common Errors

If you’re still experiencing difficulties, check for these common pitfalls:

  1. Networking Issues: Ensure your Docker network is set up correctly and the containers can communicate with each other.
  2. Firewall Rules: Check if any firewall rules are blocking connections on port 3306.
  3. Database Configuration: Verify that the magento user has sufficient privileges to connect from outside the container.

Best Practices for Docker and MySQL

For a robust setup, consider these best practices:

  • Use a dedicated database server container rather than running MySQL alongside your application servers.
  • Keep your database credentials secure by using environment variables or secret managers like Laravel’s .env file.
  • Regularly backup your databases to prevent data loss.

Conclusion: Connecting Made Easy

Remember, when connecting to services inside a Docker network, you typically don’t need SSH details. Use the container name or IP address for the hostname and ensure all credentials match exactly.

If you’re looking for more advanced techniques in managing MySQL with Laravel, I recommend checking out this guide on using Laravel’s database configuration.

With these steps, you should now be able to connect to your Percona MySQL server running inside a Docker container using MySQL Workbench. Happy coding!

Magento 2 Database Configuration Errors

Our network