Skip to content

Fix MySQL Workbench Connection – Cannot Connect to Database Server

DodaTech Updated 2026-06-24 2 min read

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.

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-address and skip-networking after 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.1 to isolate the issue.

Common Mistakes with workbench connect

  1. Misunderstanding that String is [Char] with poor performance for large text operations
  2. Using foldl instead of foldl' causing stack overflow on large lists
  3. 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

**Q: What socket path does mysql_secure_installation use?**

A: Usually /var/run/mysqld/mysqld.sock on Debian/Ubuntu or /tmp/mysql.sock on RHEL.

**Q: Can I use SSH tunnelling with MySQL Workbench?**

A: Yes β€” set Connection Method to Standard TCP/IP over SSH and fill in the SSH host, username, and key.

**Q: Why does Workbench say "Authentication plugin 'Caching_sha2_password' cannot be loaded"?**

A: The MySQL 8 default plugin is <a href="/system-design/caching/">Caching</a>_sha2_password. Use the native password plugin or upgrade Workbench.

**Q: How do I fix "Lost connection to MySQL server during query"?**

A: Increase net_read_timeout and net_write_timeout in my.cnf, and raise max_allowed_packet.


Comprehensive MySQL connection troubleshooting is in the DodaTech MySQL Workbench course.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro