localhost:3306 — MySQL

MySQL is the most deployed database in the world. WordPress runs on it. Every LAMP stack uses it. If you're doing PHP development with XAMPP, WAMP, MAMP, or Laragon, MySQL is already listening on port 3306 in the background. It's also the database behind most Laravel, Drupal, Joomla, and Magento installations — basically the entire PHP ecosystem.

MariaDB, the community fork created by MySQL's original developer after Oracle acquired it, also defaults to port 3306 and is wire-compatible — meaning you use the exact same connection strings, same tools, same drivers. If your Linux distribution installed MariaDB instead of MySQL, everything in this guide still applies.

Connecting to MySQL

Command Line

# Connect as root (prompted for password)
mysql -u root -p

# Connect to a specific database
mysql -u root -p myapp

# Run a quick query without entering the shell
mysql -u root -p -e "SHOW DATABASES;"

# Common commands once connected:
SHOW DATABASES;
USE myapp;
SHOW TABLES;
DESCRIBE users;
SELECT * FROM users LIMIT 10;

Connection Strings by Language

# PHP (PDO — the modern way)
$pdo = new PDO('mysql:host=localhost;port=3306;dbname=myapp', 'root', 'password');

# PHP (mysqli — older but still common)
$conn = new mysqli('localhost', 'root', 'password', 'myapp');

# WordPress (wp-config.php)
define('DB_HOST', 'localhost');
define('DB_NAME', 'wordpress');
define('DB_USER', 'root');
define('DB_PASSWORD', 'password');

# Node.js (mysql2 — faster than mysql package)
const mysql = require('mysql2');
const conn = mysql.createConnection({
  host: 'localhost', port: 3306,
  user: 'root', password: 'password',
  database: 'myapp'
});

# Python (mysql-connector-python)
import mysql.connector
conn = mysql.connector.connect(
    host="localhost", port=3306,
    user="root", password="password",
    database="myapp"
)

# Django (settings.py)
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'myapp',
        'USER': 'root',
        'PASSWORD': 'password',
        'HOST': 'localhost',
        'PORT': '3306',
    }
}

# Java (JDBC)
jdbc:mysql://localhost:3306/myapp?useSSL=false&serverTimezone=UTC

# Laravel (.env)
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=myapp
DB_USERNAME=root
DB_PASSWORD=password

Where Is MySQL Running?

If you installed MySQL through a local dev environment, it's probably managed by that tool:

EnvironmentHow MySQL StartsConfig Location
XAMPPXAMPP Control Panel → MySQL Startxampp/mysql/bin/my.ini
LaragonAuto-starts with Laragonlaragon/bin/mysql/my.ini
MAMPMAMP app → Start Servers/Applications/MAMP/conf/my.cnf
Homebrew (Mac)brew services start mysql/opt/homebrew/etc/my.cnf
apt (Ubuntu)sudo systemctl start mysql/etc/mysql/mysql.conf.d/mysqld.cnf
Dockerdocker run -p 3306:3306 mysql:8Container internal

Managing MySQL with phpMyAdmin

phpMyAdmin is the classic web-based GUI for MySQL. If you're using XAMPP, MAMP, or Laragon, it's pre-installed — typically accessible at localhost/phpmyadmin. It lets you browse tables, run SQL queries, import/export databases, and manage users — all through your browser. Not the prettiest tool, but it gets the job done and practically everyone who's worked with MySQL has used it.

For a more modern desktop GUI, MySQL Workbench (free, from Oracle) or DBeaver (free, supports multiple databases) are solid alternatives.

Creating a Database and User

-- Login as root first
mysql -u root -p

-- Create a database
CREATE DATABASE myapp CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- Create a user with a password
CREATE USER 'myappuser'@'localhost' IDENTIFIED BY 'securepassword';

-- Grant permissions
GRANT ALL PRIVILEGES ON myapp.* TO 'myappuser'@'localhost';
FLUSH PRIVILEGES;

Always use utf8mb4 encoding, not utf8. MySQL's "utf8" is actually a 3-byte subset that can't store emoji and some international characters. utf8mb4 is real UTF-8.

Fixing Common Errors

"Access denied for user 'root'@'localhost'" — the root password isn't what you think. On fresh MySQL 8 installs, the root account might use auth_socket authentication (Linux) which means it only accepts connections from the system root user. Fix: sudo mysql to connect without a password, then ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'newpassword';

"Can't connect to local MySQL server through socket" — MySQL isn't running, or the socket file path is wrong. On Linux, check sudo systemctl status mysql. On XAMPP, make sure MySQL is started in the control panel. The socket file is usually at /var/run/mysqld/mysqld.sock or /tmp/mysql.sock.

"Port 3306 already in use" — another MySQL instance (or MariaDB) is already running. Common when XAMPP installs its own MySQL but you also have a system-level MySQL service. Stop one of them: sudo systemctl stop mysql for the system service, or stop it in the XAMPP control panel.

"Authentication plugin 'caching_sha2_password' cannot be loaded" — MySQL 8 changed the default auth method. Older PHP/MySQL clients don't support it. Fix: ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';

MySQL vs. MariaDB

For most web development, they're interchangeable. MariaDB is what ships by default on many Linux distributions now. It uses the same port (3306), same protocol, same SQL syntax, and the same tools work with both. The divergence is mainly in advanced features — MariaDB has columnar storage and different optimizer strategies, while MySQL has features like invisible indexes and histograms. For a WordPress site or typical web app, pick whichever your system installed and don't worry about it.