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

How to Connect MySQL Workbench to a MySQL Docker Container?

DDD
Release: 2024-11-26 03:11:09
Original
544 people have browsed it

How to Connect MySQL Workbench to a MySQL Docker Container?

Connecting MySQL Workbench to MySQL Running in Docker

Accessing MySQL within a Docker container is straightforward, but connecting to it from your local machine can be challenging due to default connection restrictions. However, by making a few adjustments to the MySQL container, you can allow external connections.

Modify MySQL Connection Settings

Start by creating a MySQL container with required port mappings:

docker run -p 3306:3306 --name=mysql57 -d mysql/mysql-server:5.7
Copy after login

Obtain the default password for fresh installations:

docker logs mysql57 2>&1 | grep GENERATED
Copy after login

Connect to MySQL using the command line:

docker exec -it mysql57 mysql -uroot -p
Copy after login

If necessary, change the root password using the ALTER USER command.

Execute the following SQL statement:

update mysql.user set host = '%' where user='root';
Copy after login

Restart the Container

Once the settings have been adjusted, restart the container:

docker restart mysql57
Copy after login

Connect from MySQL Workbench

You should now be able to connect to MySQL from MySQL Workbench using the following settings:

  • Host: 0.0.0.0
  • Port: 3306

Verifying the user's host settings will show:

select host, user from mysql.user;
+-----------+---------------+
| host      | user          |
+-----------+---------------+
| %         | root          |
| localhost | healthchecker |
| localhost | mysql.session |
| localhost | mysql.sys     |
+-----------+---------------+
Copy after login

The above is the detailed content of How to Connect MySQL Workbench to a MySQL Docker Container?. 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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template