Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't login as root into MySQL container

I have a docker-compose file setup like this:

version: '3'
services:
  database:
  image: mysql:5.6
  volumes:
    - dbdata:/var/lib/mysql
  environment:
    - "MYSQL_DATABASE=my_database_name"
    - "MYSQL_USER=my_database_user"
    - "MYSQL_PASSWORD=my_database_password"
    - "MYSQL_ROOT_PASSWORD=my_root_password"
  ports:
    - "33061:3306"

volumes: dbdata:

I'm trying to login to the mysql cli client with root user & password (by first going into the container itself):

mysql -uroot -pmy_root_password

But I keep getting this error:

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
like image 800
mattyh88 Avatar asked Jul 16 '18 17:07

mattyh88


1 Answers

I didn't set the mysql root password env var from the very beginning. I had to remove the created volume "dbdata" and run docker-compose up again. That fixed it. Thanks for the help!

like image 138
mattyh88 Avatar answered Sep 29 '22 02:09

mattyh88