Im trying to move some Wordpress sites into Docker running locally on a Centos7 machine.
I can bring the WP & MYSQL container up fine but then I get nothing in the browser and if I inspect the logs I get errors about root being denied.
This is the output from the Mysql container logs and the WP container logs:
Version: '5.7.23' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server (GPL)
2018-09-07T06:26:23.117937Z 2 [Note] Access denied for user 'root'@'172.18.0.3' (using password: YES)
Warning: mysqli::__construct(): (HY000/1045): Access denied for user 'root'@'172.18.0.3' (using password: YES) in Standard input code on line 22
MySQL Connection Error: (1045) Access denied for user 'root'@'172.18.0.3' (using password: YES)
The mysql root pw is correct and I can exec into the mysql container and login using that pw just fine, I can also see that my production sql file from ./data/mysite.sql is loaded there too.
This is my compose yml file:
`version: '2'
services:
db:
image: mysql:5.7
volumes:
- ./data:/docker-entrypoint-initdb.d
- ./db:/var/lib/mysql
restart: always
environment:
- MYSQL_ROOT_HOST=%
- MYSQL_ROOT_PASSWORD=wordpress
- MYSQL_DATABASE=mysite_wp
- MYSQL_USER=mysite_user
- MYSQL_PASSWORD=mypass
wordpress:
depends_on:
- db
image: wordpress:4.9.8-fpm-alpine
ports:
- "8000:80"
restart: always
environment:
- WORDPRESS_DB_HOST=db:3306
- WORDPRESS_DB_PASSWORD=mypass
volumes:
- ./src:/var/www/html/
`
I have been trying this for almost 2 days now with a mixture of different mysql & WP versions but still no luck. Im deleting my ./db folder after I do docker-compose down each time to make sure everything starts correctly each time also.
I have also tried other suggestions from related issues such as this and this but still no luck.
If you exec into the container you're logging in as root@localhost, so maybe a) root@'%' does not exist, or it has a different password?
Note that if ./db/ was already populated with a database when you start the container, the environment variables won't have any effect, as they are only used for init of a fresh database.
When you exec in, maybe try setting the password for the root@% user manually and see if that resolves it.
I was mostly trying it without that 'MYSQL_ROOT_HOST' and just added that as saw someone else had success with it but it didnt work for me sadly. I was able to exec in and list all the users and saw host '%' for root which is correct I believe. I will try to exec in again and manually reset the pw as you suggested, thanks.
MYSQL_ROOT_HOST="%" is the default on the mysql image, but on the mysql/mysql-server image(which is maintained by Oracle), it defaults to empty, meaning only the root@localhost user is created, so for that image it might have helped.
Similarly, if your database was created with standard 5.7+ packages, either native or from upstream, only root@localhost is created by default.
Issue seems resolved so going to close
I had same issue, turns out my password contained comma, which in powershell is array separator. If that is the issue put your pwd in quotes, or check the actual password in Kitematic
Note that if ./db/ was already populated with a database when you start the container, the environment variables won't have any effect, as they are only used for init of a fresh database.
This was my problem, my db was pre-populated but i kept creating new env variables.
Thanks @ltangvald
When you exec in, maybe try setting the password for the root@% user manually and see if that resolves it.
how to setting the pw user manually?
idk how it works. can't connect to database
Most helpful comment
If you exec into the container you're logging in as root@localhost, so maybe a) root@'%' does not exist, or it has a different password?
Note that if ./db/ was already populated with a database when you start the container, the environment variables won't have any effect, as they are only used for init of a fresh database.
When you exec in, maybe try setting the password for the root@% user manually and see if that resolves it.