🇩🇪 DE 🇬🇧 EN

Connect Database

This guide shows you how to connect to your MariaDB/MySQL database – from the command line, with phpMyAdmin or from your applications. MariaDB and MySQL are the most commonly used database systems for websites, forums, shops and game servers.

Note: Detailed subpages on database management and optimization can be found in the left navigation.

Connection details – what you need

For every connection you need these five parameters:

Parameter Description Typical Value
Host Server address of the database localhost or 127.0.0.1
Port Database port 3306 (default)
Username Your database user e.g. root or a custom user
Password User's password Your assigned password
Database Name Name of the database e.g. wordpress, fivem

Method 1: Via Command Line (SSH)

Connect directly on your server – the fastest method:

# Connect to database
mysql -u username -p

# Enter password (doesn't appear on screen)
# After successful login, the mysql> prompt appears

# Select database
USE databasename;

# Show tables
SHOW TABLES;

# End connection
exit;

Connect with host and port

# External database
mysql -h 192.168.1.100 -P 3306 -u username -p databasename

Method 2: Via phpMyAdmin (Web Interface)

phpMyAdmin is the most popular web interface for MySQL/MariaDB. Here's how to find it:

Log in with your database username and password. You'll immediately see all your databases in the left sidebar.

Method 3: From an Application

PHP (e.g. WordPress, custom website)

<?php
$servername = "localhost";
$username = "my_user";
$password = "my_password";
$dbname = "my_database";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
echo "Connection successful";
?>

Node.js (e.g. FiveM, n8n, custom API)

const mysql = require('mysql2');

const connection = mysql.createConnection({
    host: 'localhost',
    user: 'my_user',
    password: 'my_password',
    database: 'my_database'
});

connection.connect((err) => {
    if (err) {
        console.error('Connection failed: ', err);
        return;
    }
    console.log('Connection successful');
});

Python

import mysql.connector

connection = mysql.connector.connect(
    host="localhost",
    user="my_user",
    password="my_password",
    database="my_database"
)

if connection.is_connected():
    print("Connection successful")

Method 4: Via Graphical Client (HeidiSQL, DBeaver)

For Windows users, graphical clients are more convenient than the command line:

In all clients, enter host, port, username, password and click "Connect".

Troubleshooting Connection Problems

"Access denied for user":

"Can't connect to MySQL server on 'localhost'":

External connections not possible:

Create Database User (Plesk)

  1. Log in to Plesk
  2. Go to Databases
  3. Click Add Database
  4. Set a database name and a username
  5. Set a secure password
  6. Select Access from any host if external connections should be allowed
  7. Click OK

Create Database User (Command Line)

# Log in as root
sudo mysql

# Create user
CREATE USER 'new_user'@'localhost' IDENTIFIED BY 'secure_password';

# Create database
CREATE DATABASE new_database;

# Grant all privileges for this database
GRANT ALL PRIVILEGES ON new_database.* TO 'new_user'@'localhost';

# Apply changes
FLUSH PRIVILEGES;
exit;

Detailed guides on database optimization and security can be found in the articles in the left navigation.