← Back to Error Index
root@linuxfix:~/mysql_connection_refused$
mysql connection refused
MySQL connection refused or server not running

Solutions

Prerequisites: Start by updating your system to resolve common issues and ensure the solutions provided below are compatible with your current environment.
check_latest_version && sudo apt update && sudo apt upgrade -y
Start MySQL service

Start MySQL server:

sudo systemctl start mysql
sudo systemctl status mysql
sudo service mysql start
Check MySQL configuration

Verify MySQL settings:

sudo cat /etc/mysql/my.cnf
mysql -u root -p -e "SHOW VARIABLES LIKE 'port';"
netstat -tlnp | grep 3306
Test connection

Test MySQL connectivity:

mysql -u username -p
telnet localhost 3306
mysqladmin ping

What is mysql connection refused?

MySQL server is not running, not listening on expected port, or connection blocked.

Common scenarios: Service stopped, wrong port, firewall blocking, or binding to localhost only.

Common Causes

  • MySQL service stopped
  • Binding to localhost only
  • Firewall blocking port
  • Wrong port number
  • Too many connections

Debugging Tips

ps aux | grep mysql
tail -f /var/log/mysql/error.log
ss -tlnp | grep 3306

Prevention

  • Monitor MySQL service
  • Configure auto-start
  • Set proper bind-address
  • Regular health checks
mysql database connection service