I'm trying to use docker-compose to connect to a MySQL database on my local computer, I wrote the following code in the docker-compose file:
db-my-sql: image: mysql:latest container_name: mysql_db restart: always environment: MYSQL_DATABASE: "xyz" MYSQL_ROOT_PASSWORD: "root1234!" ports: - "3307:3306" network_mode: "host"
Then I get the following error:
mysql.connector.errors.DatabaseError: 2003 (HY000): Unable to connect to MySQL server (99) on 'localhost:3306'
Thank you very much for your help and solution How to connect to MySQL from your local computer.
Thanks!
P粉7648364482023-12-23 14:46:29
This is because you have a port conflict. If 3306 is used in your machine (probably a MYSQL process) you can either kill the process using that port or just use another port for your docker.