Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Databases and Redis

MySQL Workbench says it cannot connect to the server on localhost:3306

ErrorCan't connect to MySQL server on 'localhost' (10061)

Short answer

Workbench only shows what the server answered, so test the server without it first. Run mysqladmin against 127.0.0.1 and port 3306. If that is refused, the server is stopped, networking is turned off, the port differs, or a firewall blocks it. If mysqladmin works, the fault is in the Workbench connection fields.

  • Applies to MySQL Server 8.4, MySQL Workbench 8.0, Ubuntu 24.04, Windows 11
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Take Workbench out of the picture. Ask the server for its version over TCP on the loopback address. The answer separates a dead server from a wrong Workbench setting.

    mysqladmin -h 127.0.0.1 --port=3306 -u root -p version
  2. 2Match what you see, then jump to its fix

    1. 1mysqladmin is refused and no mysqld process existsmysqld is not runningFix
    2. 2The server is running, but mysqladmin on 3306 is refusedThe server listens on another portFix
    3. 3The socket connection works, the TCP connection on 127.0.0.1 is refusedTCP networking is switched off in the serverFix
    4. 4The server is up and the port is right, but the connection is refused or hangs from another machineA firewall blocks the portFix

What does the error look like?

  • Can't connect to MySQL server on 'localhost' (10061)
  • Failed to Connect to MySQL at localhost:3306 with user root
  • Connection refused

Cause 1 of 4

mysqld is not running

1Check

Look for the server process. On Windows use Task Manager or the Services list instead.

ps xa | grep mysqld

2Fix

Start the server, then read its error log if it stops again straight away. On Ubuntu with the apt package the service is called mysql.

sudo systemctl start mysql

3Verify

mysqladmin now prints the server version.

mysqladmin -h 127.0.0.1 --port=3306 -u root -p version

Confirmed by dev.mysql.com

Did this fix it?

Cause 2 of 4

The server listens on another port

1Check

Ask the server which port it uses. Connect over the socket, which does not need the port, and read the port variable.

mysql -u root -p -e "SHOW VARIABLES LIKE 'port'"

2Fix

Put that number in the Port field of the Workbench connection (Hostname, Port, Username are on the Parameters tab). Do not guess: 3306 is only the default.

Workbench: Database > Manage Connections > Parameters > Port

3Verify

Click Test Connection in the same dialog.

mysqladmin -h 127.0.0.1 --port=3306 -u root -p version

Confirmed by dev.mysql.com

Did this fix it?

Cause 3 of 4

TCP networking is switched off in the server

1Check

A server started with skip_networking accepts no TCP/IP connections at all. Read the setting over the socket.

mysql -u root -p -e "SHOW VARIABLES LIKE 'skip_networking'"

2Fix

Remove skip_networking from the server option file, restart the server, and use the Local Socket/Pipe connection method in Workbench until you have done so.

sudo grep -R "skip.networking" /etc/mysql/
sudo systemctl restart mysql

3Verify

The TCP test now answers.

mysqladmin -h 127.0.0.1 --port=3306 -u root -p version

Confirmed by dev.mysql.com

Did this fix it?

Cause 4 of 4

A firewall blocks the port

1Check

On Linux look for rules that mention 3306. On Windows check that Windows Firewall or a security tool lets the MySQL port through.

sudo iptables -L -n | grep 3306

2Fix

Allow the MySQL port for the addresses that need it. Note that bind_address=127.0.0.1 makes the server listen on the loopback interface only, so a remote Workbench can never reach it until you change that setting.

mysql -u root -p -e "SHOW VARIABLES LIKE 'bind_address'"

3Verify

Run the TCP test from the machine that runs Workbench.

mysqladmin -h SERVER_IP --port=3306 -u root -p version

Confirmed by dev.mysql.com

Did this fix it?

How do I stop it coming back?

  • Use 127.0.0.1 rather than localhost in the Hostname field when you want TCP, because localhost may resolve to ::1 or use the socket.
  • Keep a one-line mysqladmin check in your notes so you can tell a server problem from a client problem in seconds.
  • Write the real port in the connection once you change it from 3306.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.