0

I have an already running MySQL container that I use for several other containers.

Now I'm trying to connect a wordpress container to it but I'm getting:

Error establishing a database connection

And the wp container log shows:

MySQL Connection Error: (1045) Access denied for user 'my_user'@'172.20.0.5' (using password: YES)

The mysql container is already up and running and the container's name is mysql, and I use a PHPMyAdmin container to manage it; I'm able to do so just fine (it's connected to the Mysql server container).

Here's my docker compose code for the WP container:

version: '2'

services:
  wordpress:
    image: wordpress:latest
    restart: unless-stopped
    ports:
      - 80
    environment:
      WORDPRESS_DB_HOST: mysql
      WORDPRESS_DB_USER: "my_user"
      WORDPRESS_DB_PASSWORD: "12345"
      WORDPRESS_DB_NAME: "my_user"
    volumes:
      - /f/Sites/mia:/var/www/html
    networks:
      - occms
      - ocdb

networks:
  occms:
    external:
      name: oly-cms
  ocdb:
    external:
      name: oly-db

Notes:

  • My db name and it's user name are the same: my_user
  • I already pre-created the mysql user my_user, and gave it full permissions to the my_user db. (note that the actual user and db start with a "g"; I've changed them to "my_user" for privacy in this question.)

enter image description here

  • I have pre-imported a bunch of data into the db (it's for debugging a currently in-production website, using a sql backup).
  • After starting up the wp container, I manually copied all of my in-production's wp files into the wp container's folder that has the same respective files, overwriting them.
  • When I edit the WORDPRESS_DB_HOST: variable and restart the wp container, i do see it's value reflected in the wp-config.php file.
  • In the wp-config.php I have made sure the credentials match:
define('DB_NAME', 'my_user');

/** MySQL database username */
define('DB_USER', 'my_user');

/** MySQL database password. Changed on: 3/20/2014 2:40 PM */
define('DB_PASSWORD', '12345');

/** MySQL hostname */
define('DB_HOST', 'mysql');

I was under the assumption that as long as I have both the mysql and wp containers in the same docker network, they should be able to connect to each other? Am I missing something in the WP compose code?

J. Scott Elblein
  • 4,013
  • 15
  • 58
  • 94
  • What type of network is it? – alex067 Dec 13 '19 at 18:41
  • @alex067 They are both, pre-existing bridges. – J. Scott Elblein Dec 13 '19 at 18:42
  • What if you try using the db's containers ip address & port instead? – alex067 Dec 13 '19 at 18:46
  • @alex067 It seems like it's able to "connect" to the container, and it shows the error `MySQL Connection Error: (1045) Access denied for user 'my_user'@'172.20.0.5' (using password: YES`. Just can't seem to connect to the actual db with that user or something. – J. Scott Elblein Dec 13 '19 at 18:53
  • Ok just to clarify, what was the original error? Did you receive this new error when you used the containers ip & port? – alex067 Dec 13 '19 at 18:53
  • That error is pretty straight forward, your user doesnt have enough privileges for that specific database – alex067 Dec 13 '19 at 18:54
  • @alex067 right, but like I mentioned, i've given the user full permissions to that db via phpmyadmin. – J. Scott Elblein Dec 13 '19 at 18:55
  • which MySQL version you are using? how you start DB container? – Adiii Dec 13 '19 at 19:00
  • 1
    from the screenshot, the user seem bind with `localhost`, i think it should be `user'@'%'` – Adiii Dec 13 '19 at 19:02
  • @Adiii `Server version: 8.0.18 - MySQL Community Server - GPL`. I start it up automatically with the restart policy of "always". Or sometimes manually using Portainer and just clicking "start" for the container. – J. Scott Elblein Dec 13 '19 at 19:02
  • MySQL 8 does not support plain authentication, so enable plain authentication `CREATE USER 'foo'@'%' IDENTIFIED WITH mysql_native_password BY 'bar';` then `FLUSH PRIVILEGES;` or run docker db container with `command:--default-authentication-plugin=mysql_native_password ` https://stackoverflow.com/questions/50093144/mysql-8-0-client-does-not-support-authentication-protocol-requested-by-server or you can start the container to accept plain auth, – Adiii Dec 13 '19 at 19:05
  • Does this answer your question? [MySQL ERROR 1045 (28000): Access denied for user 'bill'@'localhost' (using password: YES)](https://stackoverflow.com/questions/10299148/mysql-error-1045-28000-access-denied-for-user-billlocalhost-using-passw) – miken32 Dec 13 '19 at 20:36

1 Answers1

0

You set the variable for wordpress, not for MySQL, so this won't work.

I wrote a docker-compose to load a wordpress with my mysql:

  1. Download: https://github.com/aboutsam/wp-docker-startkit

  2. docker-compose up -d

Lamanus
  • 12,898
  • 4
  • 21
  • 47