Symptoms: Communications link failure, Connection refused, Access denied for user, MySQL connection error

Possible Causes

  • The MySQL service is not running
  • Wrong database username or password
  • bind-address is set to localhost only (remote connections are refused)
  • The firewall is blocking port 3306

Step-by-Step Fix

Step 1

Check whether the MySQL service is running

bash
sudo systemctl status mysql

Step 2

Test the username and password directly against MySQL

bash
mysql -u kullanici -p -h 127.0.0.1 veritabani_adi

Step 3

If you need remote connections, set bind-address to 0.0.0.0 in /etc/mysql/mysql.conf.d/mysqld.cnf

bash
bind-address = 0.0.0.0

Step 4

Open port 3306 in the firewall

bash
sudo ufw allow 3306/tcp

Step 5

Grant the MySQL user remote access privileges

bash
GRANT ALL PRIVILEGES ON veritabani.* TO 'kullanici'@'%' IDENTIFIED BY 'sifre'; FLUSH PRIVILEGES;