How to connect to mysql running in a container from the host machine

I am using https://github.com/sameersbn/docker-mysql to run the mysql container using docker-machine in OSX using a virtual box.

I created a new car

 docker-machine create --driver virtualbox mytest 

IP address

 docker-machine ip mytest 192.168.99.103 

I start the container as follows:

 docker run -p 3306:3306 --name mysql -d \ -v /opt/mysql/data:/var/lib/mysql \ -e 'DB_USER=sampleuser' -e 'DB_PASS=samplepass' -e 'DB_NAME=sampledb' -e 'DB_REMOTE_ROOT_NAME=root' -e 'DB_REMOTE_ROOT_PASS=samplerootpass' \ sameersbn/mysql:latest 

Now, when I try to connect to mysql in a container from my host machine, I can connect using the sampleuser user, but not as the root .

 โ–ถ mysql -u root -p -h 192.168.99.103 Enter password: ERROR 1045 (28000): Access denied for user 'root'@'192.168.99.1' (using password: YES) 

192.168.99.1 - my local laptop IP address

 โ–ถ ifconfig | grep "192" inet 192.168.99.1 netmask 0xffffff00 broadcast 192.168.99.255 
+2
source share
1 answer

By default, root only has access with localhost, 127.0.0.1 and :: 1, you need to specifically allow access from 192.168.99.1 or from anywhere, using the "%" in your user settings: see here http: //dev.mysql. com / doc / refman / 5.5 / en / default-privileges.html

0
source

Source: https://habr.com/ru/post/1243193/


All Articles