Did you mean to connect to localhost:3306?

Did you mean to connect to: mysql://localhost:3306?

Port 3306 is for database connections, not web browsers. Use your MySQL client or application to connect.

💡 Pro Tip: Port 3306 is MySQL's default port. If you're getting connection errors, check if MySQL service is running and verify your credentials.

Quick Commands for MySQL Port 3306

Check if MySQL is running:
sudo systemctl status mysql (Linux)
brew services list | grep mysql (Mac)
net start mysql (Windows)
Connect to MySQL:
mysql -u root -p
mysql -h localhost -P 3306 -u username -p
Find what's using port 3306:
lsof -i :3306 (Mac/Linux)
netstat -ano | findstr :3306 (Windows)
Start MySQL service:
sudo systemctl start mysql (Linux)
brew services start mysql (Mac)
net start mysql (Windows)

About Port 3306

Port 3306 is the default port for:

Common MySQL Connection Issues

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

This Windows error indicates MySQL service is not running:

Solutions:

  • Start MySQL service: net start mysql
  • Check Windows Services for MySQL and start it
  • Verify MySQL installation: mysql --version
  • Check if MySQL is installed at the expected path

"Access denied for user 'root'@'localhost'"

Authentication error when connecting to MySQL:

Solutions:

  • Reset MySQL root password:
    sudo mysql -u root -p
    ALTER USER 'root'@'localhost' IDENTIFIED BY 'newpassword';
    FLUSH PRIVILEGES;
  • For MySQL 8.0+, use: mysql -u root --auth-socket
  • Check if user exists: SELECT user,host FROM mysql.user;
  • Create new user if needed:
    CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';
    GRANT ALL PRIVILEGES ON *.* TO 'username'@'localhost';
    FLUSH PRIVILEGES;

"Can't connect to local MySQL server through socket"

Common on Linux/Mac when MySQL socket file is missing:

Solutions:

  • Check MySQL status: sudo systemctl status mysql
  • Find socket file: sudo find / -name "*.sock" 2>/dev/null | grep mysql
  • Start MySQL: sudo systemctl start mysql
  • Check my.cnf configuration for socket path
  • Try connecting via TCP: mysql -h 127.0.0.1 -P 3306 -u root -p

"Port 3306 is already in use"

Another process is using MySQL's port:

Solutions:

  • Find the process: lsof -i :3306 or netstat -tulpn | grep 3306
  • Stop existing MySQL: sudo systemctl stop mysql
  • Kill the process: sudo kill -9 PID
  • Change MySQL port in my.cnf:
    [mysqld]
    port = 3307
  • Restart MySQL: sudo systemctl start mysql

"Host is not allowed to connect to this MySQL server"

MySQL is blocking connections from your host:

Solutions:

  • Allow connections from your IP:
    GRANT ALL PRIVILEGES ON *.* TO 'username'@'your_ip' IDENTIFIED BY 'password';
    FLUSH PRIVILEGES;
  • For local development, bind to all interfaces in my.cnf:
    [mysqld]
    bind-address = 0.0.0.0
  • Check firewall settings
  • Verify user permissions: SELECT user,host FROM mysql.user;

Useful MySQL Resources