Fix DBeaver Connection Refused β Cannot Connect to Database
In this tutorial, you'll learn about Fix DBeaver Connection Refused. We cover key concepts, practical examples, and best practices.
You open DBeaver, click New Database Connection, fill in host, port, and credentials β and get "Connection refused: connect". The database server is running, SSH works, but DBeaver won't talk to it.
Wrong β
# On the DB server β common mistake: binding only to localhost
netstat -an | grep 3306
tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN
Your MySQL only listens on loopback. DBeaver connects from a remote machine, so the kernel rejects the TCP handshake immediately.
You try ping <server> from the DBeaver host β success. But the port is invisible.
Right β
For MySQL:
# /etc/mysql/my.cnf
[mysqld]
bind-address = 0.0.0.0
# or a specific network interface: 192.168.1.50
For PostgreSQL:
# postgresql.conf
listen_addresses = '*'
For both: Verify the port is open and listening on the right interface:
ss -tlnp | grep -E '3306|5432'
tcp LISTEN 0 128 0.0.0.0:3306 0.0.0.0:* users:(("mysqld",pid=1234))
tcp LISTEN 0 128 0.0.0.0:5432 0.0.0.0:* users:(("postgres",pid=5678))
Also check the firewall:
sudo ufw allow 3306/tcp
# or for PostgreSQL:
sudo ufw allow 5432/tcp
In DBeaver, test the connection with Test Connection β it should show:
Connected
Server: MySQL 8.0.33
Driver: MySQL 8.x
Ping: 2 ms
Root Cause
Databases bind to localhost by default for security. DBeaver runs on a different host, so the OS TCP stack rightfully refuses the connection β nothing is listening on the external interface.
Prevention
- After provisioning a database, check binding with
ss -tlnpbefore opening DBeaver. - Restrict access with a firewall instead of relying on the bind address alone.
- Use SSH tunnels for production databases β never expose ports to the internet.
- Document connection strings in a shared team vault (DBeaver supports
.dbeaver/data-sources.json).
Common Mistakes with connection refused
- Using
returnto exit a function early instead of wrapping a pure value in the monad - Mixing let bindings with <- bindings in do notation, producing type errors
- Overlapping type class instances that cause GHC to reject the program with ambiguous dispatch errors
These mistakes appear frequently in real-world DBEAVER code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.
Practice Exercise
Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.
This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.
FAQ
For deeper database connectivity labs, check the DodaTech DBeaver Mastery course.
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro