Skip to the content.

MariaDB Connection Refused

Summary

Symptoms

Root Cause

Diagnostics Performed

Remediation Steps

  1. Stopped MariaDB and inspected the data directory

    • sudo systemctl stop mariadb
    • sudo ls -la /var/lib/mysql
    • Ensured ownership:
      • sudo chown -R mysql:mysql /var/lib/mysql
  2. Initialized MariaDB system tables (creates mysql.*)

    • sudo mariadb-install-db --user=mysql --basedir=/usr --datadir=/var/lib/mysql
  3. Started the service and verified it is listening

    • sudo systemctl start mariadb
    • sudo systemctl status mariadb
    • sudo ss -ltnp | grep 3306 → listening on 127.0.0.1:3306
  4. Configured credentials and created the application database

    • Entered the shell:
      • sudo mysql
    • In MariaDB prompt:
      • ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';
      • CREATE USER IF NOT EXISTS 'root'@'127.0.0.1' IDENTIFIED BY 'root';
      • FLUSH PRIVILEGES;
      • CREATE DATABASE IF NOT EXISTS muhasebe_api CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
  5. Verified connectivity as used by the application

    • mysql -h 127.0.0.1 -P 3306 -u root -proot -e "SELECT 1;"

Rationale

Adminer Configuration (Non‑Docker)

Laravel .env (reference)

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=muhasebe_api
DB_USERNAME=root
DB_PASSWORD=root

Prevention Checklist