Unable to connect to MySQL server on 'localhost:3306' (99) - using docker-compose
P粉432906880
P粉432906880 2023-12-22 23:59:06
0
1
495

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粉432906880
P粉432906880

reply all(1)
P粉764836448

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!