简体   繁体   English

mysql-docker-container - 错误 1045 (28000):用户 'root'@'localhost' 的访问被拒绝(使用密码:NO)

[英]mysql-docker-container - ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

i am creating mysql docker container using below docker-compose file.我正在使用以下 docker-compose 文件创建 mysql docker 容器。 Service is created successfully but when i am trying to enter inside the container getting the below error ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)服务已成功创建,但是当我尝试进入容器内部时出现以下错误 ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

docker container exec -it 966 /bin/bash
root@96607883960b:/# mysql -uroot -p
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
root@96607883960b:/# 



version: '3.3'

services:
   db:
    image: mysql:5.7.29
    container_name: mysql
    deploy:
      replicas: 1
      restart_policy:
        condition: on-failure
    environment:
      - MYSQL_USER="testpass"
      - MYSQL_PASSWORD="testpass"
      - MYSQL_ROOT_PASSWORD="testpass"
    ports:
      - 33060:3306
    volumes:
      - /Users/hello/Work/Volumes/wavolumes/mysql:/var/lib/mysql

i found many articles didn't help to resolve this issue我发现很多文章都没有帮助解决这个问题

is any one having the solution for this issue?有人能解决这个问题吗?

Your connection actually works and you can verify it running the following (service should be running already:):您的连接确实有效,您可以验证它是否运行以下内容(服务应该已经在运行:):

docker-compose exec db sh -c 'mysql -uroot -p${MYSQL_ROOT_PASSWORD}'

The problem is that you are using the wrong password.问题是您使用了错误的密码。

You can see your problem very easily by running docker-compose config .您可以通过运行docker-compose config轻松查看您的问题。 You will see in the output that the double quotes are included as part of the values.您将在 output 中看到双引号包含在值中。

This version should solve your issue:此版本应该可以解决您的问题:

version: '3.3'

services:
   db:
    image: mysql:5.7.29
    container_name: mysql
    deploy:
      replicas: 1
      restart_policy:
        condition: on-failure
    environment:
      - MYSQL_USER=testpass
      - MYSQL_PASSWORD=testpass
      - MYSQL_ROOT_PASSWORD=testpass
    ports:
      - 33060:3306
    volumes:
      - /Users/hello/Work/Volumes/wavolumes/mysql:/var/lib/mysql

Stumbled upon the same error and tried the accepted solution, along with just using a Dockerfile, trying the "MYSQL_ALLOW_EMPTY_PASSWORD", the "MYSQL_RANDOM_ROOT_PASSWORD" and different mysql image tags (5.6, 5.7 and latest).偶然发现了同样的错误并尝试了接受的解决方案,以及仅使用 Dockerfile、尝试“MYSQL_ALLOW_EMPTY_PASSWORD”、“MYSQL_RANDOM_ROOT_PASSWORD”和不同的 mysql 图像标签(5.6、5.7 和最新)。 Root creds are also not working.根信用也不起作用。 I'm clearly doing something wrong.我显然做错了什么。

My compose looks like this:我的作曲看起来像这样:

version: '3.3'
services:
  db:
    image: mysql:5.7
    restart: always
    environment:
      MYSQL_USER: usr
      MYSQL_PASSWORD: pass
      MYSQL_ROOT_PASSWORD: root
    ports:
      - "3306:3306"
    volumes:
      - d:/vm/docker-volumes/mysql:/var/lib/mysql

I build it through docker-compose -f "docker-compose.yml" up -d --build command, and then try to connect to it by doing docker exec -it docker_db_1 bash -c 'mysql --protocol=tcp -u usr -p${MYSQL_PASSWORD}' and other variants.我通过docker-compose -f "docker-compose.yml" up -d --build命令构建它,然后尝试通过执行docker exec -it docker_db_1 bash -c 'mysql --protocol=tcp -u usr -p${MYSQL_PASSWORD}'来连接它docker exec -it docker_db_1 bash -c 'mysql --protocol=tcp -u usr -p${MYSQL_PASSWORD}'和其他变体。 Allways get the ERROR 1045 (28000): Access denid for user...总是得到ERROR 1045 (28000): Access denid for user...

Would you mind clarifying if you've done something else to make it work, apart from the suggested steps in the accepted answer?除了接受的答案中建议的步骤之外,您是否介意澄清一下您是否做了其他事情来使其工作?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ERROR 1045(28000):用户'root'@'localhost'拒绝访问(使用密码:NO) - ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) 错误1045(28000):用户'= root'@'localhost'的访问被拒绝(使用密码:否) - ERROR 1045 (28000): Access denied for user '=root'@'localhost' (using password: NO) 无法访问 MySQL:错误 1045 (28000):用户 'root'@'localhost' 的访问被拒绝(使用密码:是) - Cannot access MySQL : ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) Mysql 错误:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) - Mysql error: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) MySql 错误 1045 (28000): 用户 'root'@'localhost' 访问被拒绝(使用密码:NO) - MySql ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) 错误 1045 (28000):在 mysql 安装期间,用户 'root'@'localhost' 的访问被拒绝(使用密码:NO) - ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) during mysql installation 我在 ubuntu 上使用命令 sudo mysql 收到 ERROR 1045 (28000): Access denied for user 'root'@'localhost'(使用密码:NO) - I got ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) with the command sudo mysql on ubuntu 错误 1045 (28000):在“mysql 状态”中,用户 'root'@'localhost' 的访问被拒绝(使用密码:NO) - ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) in "mysql status" mysql -v ERROR 1045 (28000): Access denied for user root'@'localhost' (使用密码: NO) - mysql -v ERROR 1045 (28000): Access denied for user root'@'localhost' (using password: NO) [root @ localhost〜]#mysql -u root -p输入密码:错误1045(28000):用户'root'@'localhost'的访问被拒绝(使用密码:是) - [root@localhost ~]# mysql -u root -p Enter password: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM