fideloper / docker-mysql

A Docker container for MySQL
95 stars 50 forks source link

Host ... is not allowed to connect to this MySQL server #10

Open doxxon opened 10 years ago

doxxon commented 10 years ago

I'm trying to link an app with this db container. The setup seems fine as I can ping the db container from the app container, and I can connect to mysql from the db container.

But if I try to access the db container from the app using the default root/root credentials I receive an error: Host '172.17.0.92' is not allowed to connect to this MySQL server.

Should this work "out of the box", or do I need to change the permissions of root and/or create a new db user?

Thanks!

mtmacdonald commented 10 years ago

I think the default settings are used in /etc/mysql/my.cnf.

Which means the you can change the bind-address setting in my.cnf (e.g. comment it out to allow connections from all hosts).

I don't have an opinion on what the default should be because this isn't my repository.

fideloper commented 10 years ago

Hello! I've had a series of contributions in the recent(ish) past and haven't tested this all yet, but I see you're coming across something that seems fairly basic in that it should work.

MySQL needs to be told that it can connect to external network connections. By default it only listens on localhost, so it needs instead to bind to listen on the 172.* network. We can see this is happening here already.

The other half of this is that the root user is only allowed to accept connections made from "localhost" by default, so another user needs to be created that allows connections from all networks as well. That's probably something to add here.

doxxon commented 10 years ago

I've had a look at this. Creating a new user that accepts connections from wildcard hosts does seem to resolve the issue, without altering the default bind-address settings (currently 0.0.0.0).

Is this something you'd like a PR for, or should I make the changes locally?

fideloper commented 10 years ago

PR would be great - Making a default user for . from someuser.% would be useful to get people underway instead of having to figure it out themselves.

On Thu, Aug 14, 2014 at 9:42 PM, doxxon notifications@github.com wrote:

I've had a look at this. Creating a new user that accepts connections from wildcard hosts does seem to resolve the issue, without altering the default bind-address settings (currently 0.0.0.0).

Is this something you'd like a PR for, or should I make the changes locally?

— Reply to this email directly or view it on GitHub https://github.com/fideloper/docker-mysql/issues/10#issuecomment-52266269 .

rhinoceros commented 9 years ago

http://stackoverflow.com/questions/1559955/host-xxx-xx-xxx-xxx-is-not-allowed-to-connect-to-this-mysql-server

mysql> CREATE USER 'monty'@'localhost' IDENTIFIED BY 'somepass'; mysql> GRANT ALL PRIVILEGES ON ._ TO 'monty'@'localhost' -> WITH GRANT OPTION; mysql> CREATE USER 'monty'@'%' IDENTIFIED BY 'somepass'; mysql> GRANT ALL PRIVILEGES ON ._ TO 'monty'@'%' -> WITH GRANT OPTION;

LordRahl90 commented 7 years ago

please how do i change the docker mysql container configuration settings?? nano doesn't work

samratBasra commented 7 years ago

use can use "vi /etc/my.cnf"

vi is the default editor

prabal999 commented 6 years ago

Help Doc: https://docs.docker.com/samples/library/mysql/

Image link: https://store.docker.com/images/mysql

Command: docker run --name mysql_container_name --expose=3306 -p 3306 -v /my/own/datadir:/path/to/data/dir -e MYSQL_ROOT_PASSWORD=root_pwd -d mysql:tag --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci

mysql_container_name: docker container name

expose: contaner exposeing port

p: host buinding port

/path/to/data/dir: share path between container and host

root_pwd: mySql root password

tag: repository tag

utf8mb4: mysql server character set and collation type

utf8mb4_unicode_ci: mysql server character set and collation type

Example: docker run --expose=3306 -p 3306 --name mysql -v /my/own/datadir:/opt/mysql -e MYSQL_ROOT_PASSWORD=0112358139 -d mysql:latest --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci

Following steps to connect remotely:

docker exec -it mydb bash --> this will connect to mySql container.

echo "bind-address = 0.0.0.0" >> /etc/mysql/my.cnf --> this will update the my.cnf file.

service mysql restart --> restart the mySql service.

exit --> the mySql container.

docker inspect mysql | grep IPAddress --> grep the IP address of the contaner.

mysql -h 172.17.0.2 -u root –p --> remotely connect to the mySql.

sudo-sein commented 5 years ago

Possible couse for this error: If you are creating volume like in example db_data:/var/lib/mysql this is probably a culprit why host is not acceptable. Change it to local directory like this: /home/user/mysql:/var/lib/mysql, rebuild container, and it should be fine.

It fixed the issue for me and I didn't need to get inside container and change config file. Ad.1. Use local directory that does not need root access.

dvoracek-jakub commented 5 years ago

@sein69 What if I am running Docker on Windows and don´t have any /home/user/mysql directory?

sudo-sein commented 5 years ago

@dvoracek-jakub This is still local directory, so you can put any path that is writable and does not require administrators rights like C:/Users/dvoracek/mysql, or D:/data/my-awesome-app/mysql.

Keep in mind, that slashes may change (\ instead of /). Also AFAIK, docker on Windows, is using HyperV Virtualization, so in fact underneath you might be actually running on linux.

grodrigo commented 4 years ago

search to MYSQL_INITDB_SKIP_TZINFO=1

In my case there were two errors: the one commented here and docker didn't created my database and users automaticaly, so I added this line to my environment and it fix it for me.