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
- -h: Host (IP or domain)
- -P: Port (capital P, default 3306)
- -u: Username
- -p: Password prompt
Method 2: Via phpMyAdmin (Web Interface)
phpMyAdmin is the most popular web interface for MySQL/MariaDB. Here's how to find it:
- Webspace with Plesk: In Plesk under Databases → phpMyAdmin
- Own server: Usually at
https://your-domain.com/phpmyadminorhttp://your-ip/phpmyadmin
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:
- HeidiSQL: Free, Windows only, very simple
- DBeaver: Free, Windows/Mac/Linux, supports many database types
- TablePlus: Modern, Mac/Windows, paid with free version
In all clients, enter host, port, username, password and click "Connect".
Troubleshooting Connection Problems
"Access denied for user":
- Username or password incorrect? Check spelling
- Does the user have permissions for this database? Check with root:
SELECT user, host FROM mysql.user; SHOW GRANTS FOR 'username'@'localhost';
"Can't connect to MySQL server on 'localhost'":
- Is the database running?
sudo systemctl status mariadb # MariaDB sudo systemctl status mysql # MySQL - If not:
sudo systemctl start mariadb
External connections not possible:
- By default, MySQL only allows connections from localhost
- Check the bind address in the MySQL configuration:
sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf # Look for: bind-address = 127.0.0.1 # For external connections change to: bind-address = 0.0.0.0 - Check firewall: Port 3306 must be open
Create Database User (Plesk)
- Log in to Plesk
- Go to Databases
- Click Add Database
- Set a database name and a username
- Set a secure password
- Select Access from any host if external connections should be allowed
- 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.