简体   繁体   English

无法从 Intellij 连接到在 docker 容器中运行的 mySql - “指定的数据库用户/密码组合被拒绝”

[英]Unable to connect from Intellij to mySql running in docker container - "specified database user/password combination is rejected"

Currently unable to connect from Intellij to mySql running locally on docker container on ubuntu.目前无法从 Intellij 连接到在 ubuntu 的 docker 容器上本地运行的 mySql。

+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
| tasklogs           |
+--------------------+

+----------+-----------+------+
| DATABASE | HOST      | USER |
+----------+-----------+------+
| tasklogs | localhost | dev  |
| tasklogs | localhost | root |
+----------+-----------+------+

+-----------------------------------------------------------+
| Grants for dev@localhost                                  |
+-----------------------------------------------------------+
| GRANT USAGE ON *.* TO `dev`@`localhost`                   |
| GRANT ALL PRIVILEGES ON `tasklogs`.* TO `dev`@`localhost` |
+-----------------------------------------------------------+

docker ps -a:码头工人ps -a:

在此处输入图像描述

When I connect via intellij:当我通过 intellij 连接时:

在此处输入图像描述

ie "The specified database user/password combination is rejected: [28000][1045] Access denied for user 'dev'@'localhost' (using password: YES)"“指定的数据库用户/密码组合被拒绝:[28000][1045] 用户'dev'@'localhost'的访问被拒绝(使用密码:YES)”

I am putting in the right password.我正在输入正确的密码。

Any help really appreciated.任何帮助都非常感谢。

Thanks,谢谢,

As @danblack mentioned, I needed to connect via tcp.正如@danblack 提到的,我需要通过 tcp 连接。

1) To get the IP of the container: 1)获取容器的IP:

docker inspect mysql1

2) I changed the mysql user to allow access from all locations (as mentioned here ): 2)我更改了 mysql 用户以允许从所有位置访问(如此所述):

'dev'@'%' it was 'dev'@'localhost' previously 'dev'@'%'以前是'dev'@'localhost'

That did the trick:那成功了:

在此处输入图像描述

Solution解决方案

You didn't map your port with the localhost so you can't use localhost this is why couldn't do it你没有将你的端口映射到 localhost 所以你不能使用 localhost 这就是为什么不能这样做

ports:
  - "3306:3306"

If none of the answers above worked for you:如果以上答案都不适合您:

In my case I had forgotten to expose the port, but in addition I had mySQL running locally as well.在我的情况下,我忘记了公开端口,但此外我还让 mySQL 在本地运行。

So in order to debug this I did the following:所以为了调试这个,我做了以下事情:

mysql -h localhost -P 3306 --protocol=tcp -u root --password=password

The above was successful, and I managed to login through the terminal.以上是成功的,我设法通过终端登录。

Important note: when the container was done, the same command allowed me to login to the local (non-containerized) mySQL.重要提示:容器完成后,相同的命令允许我登录到本地(非容器化)mySQL。 Thus I was trying to identify a potential conflict between the two, since both had the same port.因此,我试图确定两者之间的潜在冲突,因为它们具有相同的端口。

Solution: I exposed the DB in the container in a different port 3309 and thus managed to connect successfully.解决方案:我将容器中的数据库暴露在不同的端口3309中,从而成功连接。

ports:
  - "3309:3306"

Also checking the following might help as well:检查以下内容也可能有所帮助:

  • In the Advanced tab, add the following value to the enabledTLSProtocols setting ( Reference here ): enabledTLSProtocols: TLSv1,TLSv1.1,TLSv1.2,TLSv1.3在 Advanced 选项卡中,将以下值添加到 enabledTLSProtocols 设置(在此处参考): enabledTLSProtocols: TLSv1,TLSv1.1,TLSv1.2,TLSv1.3
  • Driver file: MySQL Connector/J ver 8.0.15驱动文件:MySQL Connector/J ver 8.0.15

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

相关问题 使用数据库指定时,Docker MySQL容器未使用密码创建用户 - Docker mysql container not creating user with password when specified with database 从 Intellij 的数据库工具连接到 MySql Docker-Container - Connect to MySql Docker-Container from Intellij's Database Tool 无法连接到 docker 容器中的 MySQL 数据库 - Unable to connect to MySQL database in docker container 无法将 spring 连接到 docker 容器中的 mysql 数据库 - unable to connect spring to mysql database in docker container Docker mysql 容器无法连接到任何指定的 MySQL 主机 - Docker mysql container Unable to connect to any of the specified MySQL hosts 无法连接到 Mysql 5.7 运行为 docker 容器从 docker 主机使用 Z81C3BE090DAD54BF527E1 - Unable to connect to Mysql 5.7 running as docker container from docker host using mysql client 无法从另一个docker容器连接到docker容器中的mysql - Unable to connect to mysql in docker container from another docker container 在 Docker 容器内运行 Spring Boot 应用程序,无法连接 MySQL - Running Spring Boot app inside Docker container, unable to connect MySQL 无法连接到mysql docker容器 - Unable to connect to mysql docker container Docker + Airflow - 无法从 Z05B6053C41A21340AFD6FC3B234Z 容器连接到主机上的 MySQL - Docker + Airflow - Unable to connect to MySQL on host from docker container
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM