Connect to Docker MySQL container from localhost?

前端 未结 7 2288
孤街浪徒
孤街浪徒 2020-11-29 23:24

I have a docker mysql image running, following is what the docker-compose.yml file looks like:

db:
  image: mysql
  environment:
    MYSQL_ROOT_PASSWORD: \"\         


        
7条回答
  •  自闭症患者
    2020-11-30 00:21

    If your Docker MySQL host is running correctly you can connect to it from local machine, but you should specify host, port and protocol like this:

    mysql -h localhost -P 3306 --protocol=tcp -u root
    

    Because you are running MySQL inside Docker container, socket is not available and you need to connect through TCP. Setting "--protocol" in the mysql command will change that.

提交回复
热议问题