当前无法从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:
当我通过intellij连接时:
即“指定的数据库用户名/密码组合被拒绝:[28000] [1045]用户'dev'@'localhost'的访问被拒绝(使用密码:是)”
我输入了正确的密码。
任何帮助都很感激。
谢谢
答案 0 :(得分:1)
如@danblack所述,我需要通过tcp进行连接。
1)获取容器的IP:
docker inspect mysql1
2)我更改了mysql用户,以允许从所有位置进行访问(如here所述):
'dev'@'%'
以前是'dev'@'localhost'
做到了这一点:
答案 1 :(得分:1)
解决方案
您没有将端口映射到localhost,所以您不能使用localhost,这就是为什么不能这样做
ports:
- "3306:3306"