I'm trying to set up a MySQL container for developing.
So I used docker-compose
to set it up.
The container and the mysql looks OK. The thing is that I want to connect to it from a DBeaver client and I can't find how I do it.
Here is my docker-compose.yml
:
version: '2'
services:
db:
image: 'mysql:5.7'
volumes:
- '~/dev/dbs-data/mysql:/var/lib/mysql'
restart: 'always'
expose:
- '3306'
ports:
- '3306:3306'
environment:
MYSQL_ROOT_PASSWORD: 'pass'
MYSQL_DATABASE: 'db'
MYSQL_USER: 'user'
MYSQL_PASSWORD: 'pass'
When I try to connect it from DBeaver
I get:
java.sql.SQLException: null, message from server:
"Host '172.18.0.1' is not allowed to connect to this MySQL server"
I'm not trying to connect using the IP 172.18.0.1
. I tried to connect using localhost:3306
, 127.0.0.1:3306
and with the sub IP docker gave it 0.0.0.0:3306
After having success connecting on my Mac, I tried again with DBeaver on my linux and again:
Tried to connect with other tool, mysql workbench:
As you can see in the official image documention :
MYSQL_ROOT_HOST : By default, MySQL creates the 'root'@'localhost' account. This account can only be connected to from inside the container, requiring the use of the docker exec command as noted under Connect to MySQL from the MySQL Command Line Client. To allow connections from other hosts, set this environment variable. As an example, the value "172.17.0.1", which is the default Docker gateway IP, will allow connections from the Docker host machine.
So you have to set the MYSQL_ROOT_HOST
variable with the address 172.18.0.1
that you can see in the error message.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With