[英]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:检查以下内容也可能有所帮助:
enabledTLSProtocols: TLSv1,TLSv1.1,TLSv1.2,TLSv1.3
在 Advanced 选项卡中,将以下值添加到 enabledTLSProtocols 设置(在此处参考): enabledTLSProtocols: TLSv1,TLSv1.1,TLSv1.2,TLSv1.3
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.