Cannot connect to MySQL using default credentials


#1

I’m using Circle CI 2.0

I have te following MySQL configuration:

docker:
  - image: mysql:5.6
    environment:
      - MYSQL_ALLOW_EMPTY_PASSWORD=true
      - MYSQL_USER=ubuntu
      - MYSQL_PASSWORD=

When my test tries to connect with the database it throws this error:

Access denied for user 'ubuntu'@'127.0.0.1' (using password: NO)

The test was able to reach the MySQL server but it couldn’t connect using the default credentials.

Any idea why this happens?


#2

You need to specify a password. The user is only defined when you define both the user and password; neither can be null.

That’s noted under the Environment Variables section;

https://hub.docker.com/_/mysql/


#3

I’ve changed the file to look like this:

- image: mysql:5.6
    environment:
      - MYSQL_ALLOW_EMPTY_PASSWORD=yes
      - MYSQL_USER=ubuntu
      - MYSQL_PASSWORD=ubuntu

I’m getting a similar error:

Access denied for user 'ubuntu'@'%' to database 'circle_test'

Now it looks it reached the database, but it wasn’t able to connect.I also notice that the host change from 127.0.0.1 to a % and I didn’t modify any other configuration.


#4

MYSQL_ROOT_PASSWORD
This variable is mandatory and specifies the password that will be set for the MySQL root superuser account. In the above example, it was set to my-secret-pw.

I would do either:

- image: mysql:5.6
    environment:
      - MYSQL_ROOT_PASSWORD=ubuntu

and use the root user or

- image: mysql:5.6
    environment:
      - MYSQL_ROOT_PASSWORD=ubuntu
      - MYSQL_USER=ubuntu
      - MYSQL_PASSWORD=ubuntu

and maybe run something to make sure MySQL is actually up and ready to receive connections in case this is a timing issue.


#5

I tend to use something like

MYSQL_ALLOW_EMPTY_PASSWORD=true
MYSQL_ROOT_HOST=%
MYSQL_USER=ubuntu
MYSQL_PASSWORD=ubuntu

To use root, you must specify the root host or you will receive errors.

It can be helpful to debug this over SSH or locally;

https://circleci.com/docs/2.0/local-jobs/


#6

Thank you for helping me.

I did the changes and this is the config that got it working for me:

- image: mysql:5.6
    environment:
      - MYSQL_ROOT_PASSWORD=ubuntu
      - MYSQL_DATABASE=circle_test

In the test I use root as the user and everything worked as expected.


#7

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.