简体   繁体   中英

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)

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM