0

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!

2
  • 1
    Does it work if you use a password up to ...R29u, stopping before the #? Does it work if you put the MYSQL_ROOT_PASSWORD value in single quotes? Commented Jan 17, 2019 at 23:33
  • Thank you for the suggestion David, but this did not work Commented Jan 19, 2019 at 16:58

3 Answers 3

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

He specified that it's not working externally either.
You are correct. I misread the question and thought he was trying to connect a container to a MySql server running on the host machine. Maybe try adding: "- 'MYSQL_ROOT_HOST=%' " to your environment section?
1

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.

Comments

0

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 execute docker rm -v <CONTAINER_NAME>. Bring up your container afterwards.

1 Comment

Yes I had tried that following a similar site I had visited. Thank you for the suggestion though

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.