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

Fix 'Database connection failed' in MySQL on Windows Server

Database Errors Beginner 👁 1 views 📅 May 27, 2026

MySQL won't connect? Usually the service isn't running or a firewall's blocking it. Let's get you back up fast.

Quick answer (for the pros)

Run net start MySQL80 in an admin command prompt. If that fails, check services.msc to see if MySQL is disabled. Also verify port 3306 isn't blocked by Windows Firewall.

Why this happens

I've seen this error more times than I can count—usually on a Monday morning when someone's app just won't load. Client last month had a whole CRM system go dark because Windows Update decided to restart the server and the MySQL service didn't auto-start. The error code 10061 basically means the server's not listening on that port. Could be the service stopped, a firewall rule got corrupted, or MySQL crashed from a bad query. Let's rule out the obvious stuff first.

Step-by-step fix

  1. Check if MySQL service is running
    Open services.msc (press Windows+R, type it in). Look for MySQL—usually called MySQL80 or MySQL57. If it's stopped, right-click and hit Start. If it's disabled, change startup type to Automatic, then start it.
  2. Test the connection
    Open Command Prompt as admin and run:
    mysql -u root -p

    If you see the MySQL prompt, you're golden. If it hangs or throws the same error, move to step 3.
  3. Verify port 3306
    Run:
    netstat -an | findstr :3306

    If you see 0.0.0.0:3306 LISTENING, it's listening. If nothing shows, the service isn't binding properly, or it's running on a different port (unlikely but possible).
  4. Check Windows Firewall
    Go to wf.msc, look for an inbound rule allowing port 3306. If missing, create a new rule: port 3306, TCP, allow connection. Apply to all profiles. I've had cases where a security update wiped the rule clean.

If the main fix doesn't work

Try these alternatives in order:

  • Restart the server. Sounds dumb, but I've seen MySQL hang after a memory spike. A clean boot often clears it.
  • Check the MySQL error log. Look in C:\ProgramData\MySQL\MySQL Server 8.0\Data\ for a .err file. Open it, search for error or crash. Last month I found a corrupted table that killed the service—had to run mysqlcheck --repair.
  • Reinstall MySQL Connector/ODBC if you're using an app that connects via ODBC. Sometimes the driver gets messed up. Download the latest from the MySQL site.
  • Change the bind address. If MySQL is set to bind-address = 127.0.0.1, and your app tries to connect via the machine's IP, it'll fail. Change it to 0.0.0.0 in my.ini (in the MySQL install folder) and restart the service.

Prevention tips

  • Set MySQL service to start automatically. In services.msc, double-click MySQL, set Startup type to Automatic. Do this now, before the next reboot.
  • Schedule a weekly restart. I use a simple batch script:
    net stop MySQL80
    timeout /t 10
    net start MySQL80

    Run it via Task Scheduler every Sunday at 3 AM.
  • Monitor with a heartbeat. If this is a production server, set up a simple ping—like a scheduled task that runs mysql -u root -e "SELECT 1" and emails you if it fails.
  • Keep Windows Firewall rules backed up. Export them from wf.msc as a .wfw file. When a Windows update nukes them, you can restore in 30 seconds.
Real talk: 90% of the time this error is just the service being stopped or a firewall blocking the port. Don't overthink it. But if you're running a high-traffic app, invest in a proper monitoring tool—Nagios or even a cheap PRTG setup. One hour of downtime costs more than a year of monitoring.

Was this solution helpful?