Mysql not Creating database

Hey guys,

Struggling to get a container to connect to mysql properly.

Any one able to shed some light or do a PR request?

I have the following docker-compose.yml

version: '3'
services:
    webserver:
        container_name: massscan-webserver
        restart: always
        build:
            context: .
            dockerfile: server.docker
        ports:
            - 91:80
        links:
            - database
            
    database:
        container_name: massscan-database
        restart: always
        build:
            context: .
            dockerfile: mysql.docker
        environment:
            - "MYSQL_ROOT_PASSWORD=docker"
        volumes:
            - /home/host/docker/mysql-storage/:/var/lib/mysql
            - ./db/mysql.sql:/docker-entrypoint-initdb.d/mysql.sql
        ports:
            - 3306:3306

I have the following config file…

define('DB_DRIVER',	    'mysql');
define('DB_HOST',	    'massscan-database');
define('DB_USERNAME',	'root');
define('DB_PASSWORD', 	'docker');
define('DB_DATABASE', 	'docker_massscan');

My mysql file starts correctly as it’s a dump from phpmyadmin.

My project url is

Error message

SQLSTATE[HY000] [1045] Access denied for user ‘root’@‘172.24.0.3’ (using password: YES).

Does “massscan-webserver” connect to mysql using a user name and password? If so have you configured it in your webserver’s settings? There seems to exist no environment variables for “massscan-webserver” container.

hey,

yep it does i am connecting as root and the webserver is connecting using config.php that is adding during the build of the webserver.

as a trouble shooting step install mysql cli client in webserver and see if you can manually connect to mysql server using the credentials in config.php

webserver$ mysql -u root -p mysql-server

it looks to be 100% that the container is not allowed to connect to the other database container.

root@c674e4c6c541:/var/www/html# mysql -h database                                                                                                                                                                                                              
ERROR 1130 (HY000): Host '172.24.0.3' is not allowed to connect to this MySQL server

  root@c674e4c6c541:/var/www/html# mysql -h database -u docker                                                                                                                                                                                                    
ERROR 1130 (HY000): Host '172.24.0.3' is not allowed to connect to this MySQL server                                                                                                                                                                            
root@c674e4c6c541:/var/www/html# mysql -h database -u root                                                                                                                                                                                                      
ERROR 1130 (HY000): Host '172.24.0.3' is not allowed to connect to this MySQL server                                                                                                                                                                            
root@c674e4c6c541:/var/www/html#

I added this as a sql command and it has worked and it now connects.

USE `mysql`;		
UPDATE `user` SET `host` = '%' WHERE `host` = '1%'		
FLUSH PRIVILEGES;

TO connect from 172.24.0.3 you need mysql accounts

‘docker’@‘172.24.0.3’ &
‘root’@'172.24.0.3

on your mysql server

https://dev.mysql.com/doc/refman/5.7/en/account-names.html

To allow connection for a user from anyhost you can use '%"

–Siju

Alright, but understanding the details is important otherwise troubleshooting will become difficult.
–Siju