1

I try to start MySQL server with docker-compose. Here is docker-compose.yaml part:

  mysql:
    image: debezium/example-mysql
    ports:
     - "3306:3306"
    environment:
     - MYSQL_ROOT_PASSWORD=debezium
     - MYSQL_USER=mysqluser
     - MYSQL_PASSWORD=mysqlpw

moreover I started a django application with setting

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': os.environ.get('MYSQL_DB_NAME', default='db_eddy_backend'),
        'USER': os.environ.get('MYSQL_USER', default='eddy_backend'),
        'PASSWORD': os.environ.get('MYSQL_PASSWORD', default='mysqlpassword'),
        'HOST': os.environ.get('MYSQL_HOST', default='127.0.0.1'),
        'PORT': os.environ.get('MYSQL_PORT', default='3306'),
    }
}

however the django starts it pops out an error message saying

django.db.utils.OperationalError: (1045, "Access denied for user 'eddy_backend'@'172.19.0.1' (using password: YES)")

what is wrong? and how to deal with it?

Thanks to nbk's help, I tried

I tried

docker exec -it 4ac01eb11bf7 mysql -uroot -p, 
GRANT ALL PRIVILEGES ON . TO 'root'@'%' IDENTIFIED BY 'debezium'; 

but the output is

Query OK, 0 rows affected. 

And django app still met the same problem

user824624
  • 7,077
  • 27
  • 106
  • 183
  • use this https://stackoverflow.com/a/11225588/5193536 – nbk Oct 18 '20 at 23:08
  • Does this answer your question? [MySQL root access from all hosts](https://stackoverflow.com/questions/11223235/mysql-root-access-from-all-hosts) – nbk Oct 18 '20 at 23:09
  • I tried docker exec -it 4ac01eb11bf7 mysql -uroot -p, GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'debezium'; but it outputs Query OK, 0 rows affected. And django app still met the same problem – user824624 Oct 19 '20 at 01:37
  • 1
    you dind't understand the cncept, you need to ` GRANT ALL PRIVILEGES ON \*.\* TO 'eddy_backend'@'%' ;` because this user needs access from remote, root has already all privileges – nbk Oct 19 '20 at 06:26

1 Answers1

1

You should check if there is the service mysql and django on the same net

Review your networks of docker:

sudo docker network ls  

Inspect your network and make sure if there are the two services running on the same net

sudo docker inspect <the_name_net>

*Also is important to view the correct ip service:

sudo docker inspect <the_net_id> | jq '.[].NetworkSettings.IPAddress'