Fix MySQL Workbench Connection β Cannot Connect to Database Server
In this tutorial, you'll learn about Fix MySQL Workbench Connection. We cover key concepts, practical examples, and best practices.
You open MySQL Workbench, click your saved connection, and get "Can't connect to MySQL server on 'localhost:3306' (61)" β or "Access denied for user 'root'@'localhost'". The MySQL server is running, but Workbench refuses to cooperate.
Wrong β
# Check if MySQL is running
sudo systemctl status mysql
# β active (running)
Connection Method: Standard (TCP/IP)
Hostname: localhost
Port: 3306
Username: root
You get:
Can't connect to MySQL server on 'localhost:3306' (61 Connection refused)
You check the port:
ss -tlnp | grep 3306
# β nothing
MySQL is running but binding to a Unix socket only, not TCP.
Right β
Option A β Switch to Unix socket:
In MySQL Workbench, set:
Connection Method: Local Socket/Unix
Socket: /var/run/mysqld/mysqld.sock
Test connection β β
Option B β Enable TCP in MySQL:
# /etc/mysql/my.cnf or /etc/my.cnf
[mysqld]
bind-address = 127.0.0.1
# or 0.0.0.0 for remote access
skip-networking = 0 # ensure networking is on
port = 3306
Restart MySQL:
sudo systemctl restart mysql
ss -tlnp | grep 3306
tcp LISTEN 0 128 127.0.0.1:3306 0.0.0.0:*
Now TCP connection works in Workbench.
Common credential fix:
If you get Access denied:
-- Reset from terminal
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'newpass';
FLUSH PRIVILEGES;
Then update the stored password in Workbench: Manage Server Connections β Store in Keychain β Enter.
Root Cause
MySQL Workbench connects over TCP by default. Many Linux installations run MySQL with networking disabled (skip-networking) or binding only to a Unix socket. Workbench then finds no TCP listener and errors out.
Prevention
- Use Local Socket/Unix for all local connections β faster and more secure.
- If you need TCP locally, verify
bind-addressandskip-networkingafter every MySQL upgrade. - Store passwords in Workbench's keychain so you don't have to reβenter them.
- Test from the terminal first:
mysql -u root -p -h 127.0.0.1to isolate the issue.
Common Mistakes with workbench connect
- Misunderstanding that
Stringis[Char]with poor performance for large text operations - Using
foldlinstead offoldl'causing stack overflow on large lists - Forgetting
deriving (Show, Eq)on custom data types needed for debugging
These mistakes appear frequently in real-world MYSQL 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
Comprehensive MySQL connection troubleshooting is in the DodaTech MySQL Workbench course.
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro