Having a hard time trying to get to grips with mysql in docker. I have got the container running with docker-compose, but I am not able to connect to the database via any tools such as phpmyadmin, workbench or tableplus.
I have connected directly to the running container and run
mysql -uroot -p
and entered the root password which I have passed, but this fails with this error:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
Here is my docker-compose.yml file:
version: '3'
services:
db:
image: mysql
restart: always
environment:
MYSQL_DATABASE: quotes
MYSQL_USER: quotes
MYSQL_PASSWORD: P@KhzKZp)56sU8n+
MYSQL_ROOT_PASSWORD: +VrLG*<t5sq[\shR29u#n~A3^Jp*
ports:
- '3306:3306'
volumes:
- /private/mdbdata/quotes:/etc/mysql/conf.d
expose:
- '3306'
Been on this for days… hope someone can help!
3
Answers
Finally solved this one ... I had to remove all special characters from the password strings.
I tired adding single and double quotes are around the strings to see if that would allow the special characters, but that still failed. Passwords needed to be alphanumeric.
I think your container is looking for a MySQL server on ‘localhost’, which WILL NOT WORK. ‘localhost’ to a container is the container itself – NOT the host machine it’s running on.
You should be able to access the MySQL server using the host machine IP address.
Have you tried the solution provided here? Basically, if you had a container running previously, you have to explicitly purge it since docker keeps track of root passwds (via volumes) from previously instantiated containers. This happens with a lot of tools, it’s not unique to MySQL containers. A simple
docker-compose rm -v
should suffice, afterwards bring up your container. This basically deletes the old volume from the disk, removing all data from previous container instantiation.You can also call a
docker ps
, find your container and executedocker rm -v <CONTAINER_NAME>
. Bring up your container afterwards.