Database connection error

Fix 'Database connection error' in MySQL on Windows

Database Errors Beginner 👁 6 views 📅 Jul 13, 2026

MySQL won't connect? Usually a port conflict or service stopped. Here's how to fix it fast.

Quick Answer

Check if MySQL service is running in Services.msc, then verify port 3306 isn't blocked by another program using netstat -ano | findstr :3306.

What's happening?

You open your app or phpMyAdmin and see "Database connection error" or "Can't connect to MySQL server on localhost." This usually means either MySQL stopped running (often after a Windows update or power outage) or another program grabbed port 3306. I've seen this dozens of times with XAMPP, WAMP, and standalone MySQL installations on Windows 10 and 11.

The real fix is getting MySQL service back up and clearing any port conflict. Let's do it step by step.

Step-by-step fix

Step 1: Check MySQL service status

  1. Press Win + R, type services.msc, hit Enter.
  2. Scroll down to MySQL (might be named MySQL80, MySQL57, or just MySQL depending on version).
  3. Look at the Status column. If it says Running, great. If it's blank or says Stopped, you found the issue.

Expected: After step 2, you should see the service name and its current state.

Step 2: Start the service

  1. Right-click the MySQL service and choose Start.
  2. Wait 5-10 seconds. The status should change to Running.
  3. Minimize Services window (don't close it yet).
  4. Try connecting again. If it works, you're done.

Expected: After clicking Start, the status column updates to Running. If you get an error message like "Windows could not start the MySQL service on Local Computer," go to Step 3.

Step 3: Check if port 3306 is free

  1. Open Command Prompt as Administrator (right-click Start > Command Prompt (Admin) or Windows Terminal Admin).
  2. Type this command and press Enter:
netstat -ano | findstr :3306
  1. If you see a line like TCP 0.0.0.0:3306 0.0.0.0:0 LISTENING 1234, something else is using port 3306.
  2. The number at the end (1234 in this example) is the Process ID (PID). Write it down.

Expected: If you see nothing (empty result), port 3306 is free — problem is elsewhere. If you see a line, port is taken.

Step 4: Identify what's blocking the port

  1. Open Task Manager (Ctrl + Shift + Esc).
  2. Click the Details tab.
  3. Click the PID column to sort by it.
  4. Find the PID from earlier. Common culprits: Skype, another MySQL install, or a previous leftover process.
  5. Right-click that process and choose End task.
  6. Go back to Services.msc and try starting MySQL again.

Expected: After killing the process, MySQL should start without the "port in use" error.

Step 5: Change MySQL port if you can't free 3306

If you need that other program (like Skype) keeping port 3306, change MySQL's port instead:

  1. Find your MySQL config file. Common locations:
    • XAMPP: C:\xampp\mysql\bin\my.ini
    • WAMP: C:\wamp64\bin\mysql\mysql[version]\my.ini
    • Standalone: C:\ProgramData\MySQL\MySQL Server 8.0\my.ini
  2. Open the file in Notepad (right-click > Open with > Notepad).
  3. Find the line port = 3306. Change it to port = 3307 or another number above 1024.
  4. Save the file. Close Notepad.
  5. In Services.msc, restart MySQL (right-click > Restart).
  6. Update your app's connection string to use the new port number.

Expected: MySQL starts on the new port. Your app must now connect to localhost:3307 instead of localhost:3306.

Alternative fix: Reinstall MySQL service

If MySQL service won't start even after freeing the port, the service entry itself might be corrupted. Here's what worked for me:

  1. Open Command Prompt as Administrator.
  2. Stop MySQL first if it's partially running:
net stop MySQL
  1. Remove the service:
sc delete MySQL
  1. Reinstall the service. Navigate to your MySQL bin folder (example for XAMPP):
cd C:\xampp\mysql\bin
  1. Run:
mysqld --install MySQL --defaults-file="C:\xampp\mysql\bin\my.ini"
  1. Start the service from Services.msc or use:
net start MySQL

Expected: You'll see "Service installed successfully" after step 5. Then "MySQL service is starting..." followed by "The MySQL service was started successfully."

Prevention tip

Set MySQL service to start automatically so it doesn't die after a reboot:

  1. Open Services.msc.
  2. Right-click MySQL > Properties.
  3. Set Startup type to Automatic.
  4. Click Apply, then OK.

Also, if you use Skype, go to Skype's Tools > Options > Advanced > Connection and uncheck "Use port 80 and 443 for incoming connections" — that frees up port 3306 permanently. I've seen Skype cause this exact error at least 20 times.

That's it. Nine out of ten times, one of these steps gets you back up in under 5 minutes.

Was this solution helpful?