I ran my mysql in a docker container after making a docker network.
docker network create --subnet=172.19.0.0/16 network-name
docker run -p 3306:3306 --net network-name --ip 172.19.0.13 -e MYSQL_ROOT_PASSWORD=password -d
Then when I tried to connect to mysql in my local with command
mysql -uroot -p
, I got error (Error 2002 (HY000): Can't Connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
)
Then I succeeded with command mysql -u root -p -h 172.19.0.13
I thought I connected my localhost port 3306 with docker container's 3306 port. Why can't I connect to mysql through localhost port?