How to connect to mysql running in container from

2019-07-19 09:06发布

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条回答
狗以群分
2楼-- · 2019-07-19 09:28

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

查看更多
登录 后发表回答