MySQL Workbench says it cannot connect to the server on localhost:3306
Can'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.
Fix it fast
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 version2Match what you see, then jump to its fix
- 1
mysqladmin is refused and no mysqld process existsmysqld is not runningFix - 2
The server is running, but mysqladmin on 3306 is refusedThe server listens on another portFix - 3
The socket connection works, the TCP connection on 127.0.0.1 is refusedTCP networking is switched off in the serverFix - 4
The server is up and the port is right, but the connection is refused or hangs from another machineA firewall blocks the portFix
- 1
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 rootConnection 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 mysqld2Fix
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 mysql3Verify
mysqladmin now prints the server version.
mysqladmin -h 127.0.0.1 --port=3306 -u root -p versionConfirmed by dev.mysql.com
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 > Port3Verify
Click Test Connection in the same dialog.
mysqladmin -h 127.0.0.1 --port=3306 -u root -p versionConfirmed by dev.mysql.com
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 mysql3Verify
The TCP test now answers.
mysqladmin -h 127.0.0.1 --port=3306 -u root -p versionConfirmed by dev.mysql.com
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 33062Fix
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 versionConfirmed by dev.mysql.com
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:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- ShopGoAn e-commerce aggregator with a Python scraping engine behind its catalog, past 10K Google Play downloads.
Related fixes
Databases
Installing the Airflow MySQL provider fails on pkg-config or mysqlclient
Building the mysqlclient wheel fails during the install
The Airflow MySQL provider depends on mysqlclient, which pip compiles against the MySQL C client library.
2 causes, each with a fixDatabases
Compiling a C or C++ program that includes mysql.h fails
undefined reference to `mysql_init'
The compiler only finds mysql.h when the MySQL client development files are installed and their folder is on the include path.
3 causes, each with a fixDatabases
An EC2 instance cannot reach its RDS database
Could not open connection to the host, on port <port>: Connect failed
RDS denies all access until a security group allows it.
3 causes, each with a fixDatabases
Locked out of a fresh MariaDB install as root on Mac or Linux
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
A fresh MariaDB root account is not a normal password account.
3 causes, each with a fixDatabases
An Aria table fails with 'Read page with wrong checksum' (error 1030, code 176)
ERROR 1030 (HY000): Got error 176 "Read page with wrong checksum" from storage engine Aria
Code 176 means MariaDB's Aria engine read a data or index page whose checksum does not match, so that table file is damaged.
3 causes, each with a fixDatabases
The client cannot open a TCP connection to MariaDB or MySQL (error 2003)
ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1:3306' (111)
Error 2003 means the client tried a TCP connection to the host and port and nobody answered.
4 causes, each with a fix