Mysql: MySQL Connection Error: (1130) Host 'xxx.xx.x.x' is not allowed to connect to this MySQL server

Created on 23 Mar 2016  路  9Comments  路  Source: docker-library/mysql

Hi,

I'm trying to get [a wordpress container linked to a mysql container] and [a website linked to his api linked to its db] behind a reverse proxy nginx (using jwilder's solution), all on the same cluster on a ECS instance.

I have tried the 'usual way' of doing it, equivalent to :

forum:
  image: wordpress:latest
  working_dir: /var/www/html
  links:
   - forumdb:mysql
  volumes:
    - $GOPATH//wordpress/wp-content/:/var/www/html/wp-content
  environment:
    WORDPRESS_DB_PASSWORD: password
    VIRTUAL_HOST: forum.docker.dev
forumdb:
  image: mysql:latest
  restart: always
  environment:
    MYSQL_ROOT_PASSWORD: password
    MYSQL_DATABASE: wordpress

and tried adding WORDPRESS_DB_USER not to use the root, but unsuccesfully ; I always get those errors :

MySQL Connection Error: (1130) Host '172.17.0.8' is not allowed to connect to this MySQL server
Warning: mysqli::mysqli(): (HY000/1130): Host '172.17.0.8' is not allowed to connect to this MySQL server in - on line 10

The Host IP can change when I rerun the containers.

In the MySQL container I have :

mysql> show grants;
+---------------------------------------------------------------------+
| Grants for root@localhost                                           |
+---------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION |
| GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION        |
+---------------------------------------------------------------------+

I used those docker images several months ago, without any trouble ; my understanding is that now the default conf doesn't authorize the WP container to connect to the db as it is not on localhost, as it is in another container .
Do I understand it right ?
What is the right solution to get this work ?

Thanks,

Most helpful comment

No problem! In general the docker image should work fine with existing databases, but user access may need to be changed since you're moving the server to its own host.

All 9 comments

I would like to add that this is not related to the fact that the wordpress container is trying to connect before the mysql container is ready : I get the same error if I run the container manually.

Are you starting the container without mapping an existing database to the container's /var/lib/mysql?
When initializing a new database, the mysql container should create a 'root'@'%' user, since no connections from outside the container could use the 'root'@'localhost' user.

@ltangvald you were absolutely right, I forgot to mention that I have a volume set for /var/lib/mysql...I emptied it, restarted all and now it works fine. Thanks,

No problem! In general the docker image should work fine with existing databases, but user access may need to be changed since you're moving the server to its own host.

I'm having this issue now. I have an existing volume, and I believe the container has changed IP address (isn't this completely normal?). No longer sure what's causing it. All I've done is start the container. It's never crashed, and never been killed.

@SeerUK same here.

In my case, I had previously done docker rm -f $container_id while the db was initializing, so later, I had to delete the directory mounted on /var/lib/mysql and then run the container.

You could try running
docker exec -it mysql -uroot -p
That should let you log in as root. Then run
select user, host from mysql.user;
which will give you the allowed host pattern for each user.
Have you changed any config files? Started mapping custom configs in /etc/mysql/conf.d or similar?

@ltangvald Yes, that I can always do, but I was just experimenting and the data was not important at all, so I just went ahead and nuked /var/lib/mysql.

Was this page helpful?
0 / 5 - 0 ratings