Reputation: 1544
Currently unable to connect from Intellij to mySql running locally on docker container on ubuntu.
+--------------------+
| 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:
When I connect via intellij:
i.e. "The specified database user/password combination is rejected: [28000][1045] Access denied for user 'dev'@'localhost' (using password: YES)"
I am putting in the right password.
Any help really appreciated.
Thanks,
Upvotes: 19
Views: 24465
Reputation: 3011
As an addition to @Hurricane's response, I am attaching the screenshot of
docker inspect yourContainerID
command
For me IP was: 172.17.0.2
If you're using Linux(MacOS) you can also run
docker inspect yourContainerID | grep "IPAddress"
to directly retrieve IPAddress
My problem was with volumes, so I created a docker-compose.yml
file and run docker compose up
version: '3.1'
services:
world_x:
image: mysql
environment:
MYSQL_DATABASE: 'world_x'
MYSQL_USER: testuser
MYSQL_PASSWORD: testpass
MYSQL_ROOT_PASSWORD: testsuperpass
ports:
- "3306:3306"
expose:
- '3306'
volumes:
- mysql-volume:/var/lib/mysql
restart: unless-stopped
volumes:
mysql-volume:
Upvotes: 3
Reputation: 1168
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.
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. 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.
ports:
- "3309:3306"
Also checking the following might help as well:
enabledTLSProtocols: TLSv1,TLSv1.1,TLSv1.2,TLSv1.3
Upvotes: 1
Reputation: 593
Solution
You didn't map your port with the localhost so you can't use localhost this is why couldn't do it
ports:
- "3306:3306"
Upvotes: 6