How to connect to mysql running in container from host machine

半城伤御伤魂 提交于 2019-12-10 23:18:10

问题


I'm using https://github.com/sameersbn/docker-mysql to run a mysql container using docker-machine in OSX with virtualbox.

I created a new machine

docker-machine create --driver virtualbox mytest

The IP is

docker-machine ip mytest
192.168.99.103

I run the container like this:

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 the mysql in the container from my hostmachine I can connect using user sampleuser but not as user 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 is my local laptops ip address

▶ ifconfig | grep "192"
    inet 192.168.99.1 netmask 0xffffff00 broadcast 192.168.99.255

回答1:


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



来源:https://stackoverflow.com/questions/34905765/how-to-connect-to-mysql-running-in-container-from-host-machine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!