docker-compose中的MySQL-访问被拒绝 [英] MySQL in docker-compose -- access denied

查看:1362
本文介绍了docker-compose中的MySQL-访问被拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试用docker-compose启动MySQL服务器.这是docker-compose.yaml部分:

I try to start MySQL server with docker-compose. Here is docker-compose.yaml part:

  mysql:
    restart: always
    image: mysql:latest
    ports:
    - "3306:3306"
    volumes:
    - /Users/user/Documents/.docker/mysql/config:/etc/mysql/
    - /Users/user/Documents/.docker/mysql/data:/var/lib/mysql
    environment:
    - MYSQL_ROOT_PASSWORD='123'
    - MYSQL_ROOT_HOST='172.18.0.1'

您会看到我已经指定了root密码和主机,正如此处 .然后,我尝试连接到数据库(如果重要的话,请使用Intellij Idea):

You see I've specified root password and host as it is said here. Then I try to connect to db (using Intellij Idea if that matters):

jdbc:mysql://localhost:3306/?user=root&password=123&ssl=false

但是它不接受凭据并写入日志:

But it doesn't accept the credentials and writes to log:

Access denied for user 'root'@'172.18.0.1' (using password: YES)

请提供有关修复方法的建议.谢谢.

Please advise on how to fix it. Thanks.

推荐答案

当它们不同时,很可能已经初始化了mysql数据目录:

Most likely you have initialized the mysql data directory when these were different:

environment:
- MYSQL_ROOT_PASSWORD='123'
- MYSQL_ROOT_HOST='172.18.0.1'

MySQL映像仅在从头启动/var/lib/mysql目录时才接受这些var.

MySQL image only honors those vars when start a /var/lib/mysql directory from scratch.

因此,如果您不关心数据,请清空卷:/Users/user/Documents/.docker/mysql/data,或从mysql终端手动更改凭据.

So if you don't care about the data, empty your volume: /Users/user/Documents/.docker/mysql/data, or change the credentials manually from mysql terminal.

这篇关于docker-compose中的MySQL-访问被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆