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:
Start the MySQL Container:
docker run -p 3306:3306 --name=mysql57 -d mysql/mysql-server:5.7
Get the Default Password:
docker logs mysql57 2>&1 | grep GENERATED
Connect to MySQL:
docker exec -it mysql57 mysql -uroot -p
Alter User Settings:
update mysql.user set host = '%' where user='root';
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!