Connecting to MariaDB Databases

MariaDB is a community-developed fork of the MySQL relational database management system and is used at Opalstack to provide MySQL-compatible database services.

This document shows how to connect to your MariaDB databases on Opalstack from clients and applications that use MariaDB and/or MySQL databases.

Connection Parameters

The parameters used to connect to a MariaDB database on your Opalstack server are:

  • Host: localhost for local connections made directly on the server, or for remote connections from an external host (replace 'opalN' with your Opalstack server hostname, available on the control panel dashboard). Note that you must enable external access on your MariaDB database before you can make remote connections to your database.
  • Port: 3306
  • Socket: /var/lib/mysql/mysql.sock
  • Database name: your MariaDB database name
  • Database user name: your MariaDB database user name
  • Database user password: your MariaDB database user password

Note that many applications use a default configuration with the host as localhost and the port and socket as mentioned above so those parameters might be optional or not present in your application settings. Consult your application's documentation for its specific configuration requirements.

Connection Examples

The following examples use mydb as the MariaDB database name, mydbuser as the database user name, and mydbpassword as the database user password. Replace them with your own database name and credentials.

Command line client

First log in to a SSH session as a shell user on your server, then...

mysql -p -u mydbuser mydb

...and enter your database user password when prompted.


First install the mysqlclient library in your environment...

source env/bin/activate
pip install mysqlclient

... then in your Python code:

import MySQLdb as mysql
conn = mysql.connect(host='localhost', user='mydbuser',
                     password='mydbpassword', database='mydb')


In your PHP code:

$conn = new mysqli("localhost", "mydbuser", "mydbpassword", "mydb");


First install the mysql package into your Node.js project directory...

npm install mysql

... then in your Javascript code:

var mysql = require('mysql');
var conn = mysql.createConnection({
    host: 'localhost',
    user: 'mydbuser',
    password: 'mydbpassword',
    database: 'mydb'


First install the mysql2 gem...

gem install mysql2

... then in your Ruby code:

require 'mysql2'
conn = => "localhost", :username => "mydbuser", 
                          :database => "mydb", :password => "mydbpassword")

Connecting to a MariaDB Database Remotely via a SSH Tunnel

Opalstack's control panel gives you the option to enable external access for your MariaDB databases, but for additional security we recommend that you make remote connections through a SSH tunnel.

To use a SSH tunnel for MariaDB access:


Create a MariaDB and user.


Create a shell user.


On the client machine making the remote connection (for example, your own computer) open your terminal application and run the following command to establish the tunnel, replacing with your shell username and Opalstack server hostname:

ssh -L 3306: -N


  • If you have a MySQL server already running on the client machine, then you will need to change the local port used by the tunnel. The following example uses port 3307 as the local port: ssh -L 3307: -N

  • If you're using PuTTY for your SSH connections, use 3306 as the source port and as the destination under "Category > Connection > SSH > Tunnels".


Finally, on the client machine configure your application to connect to your database with the following parameters:

  • Host:
  • Port: 3306 (or whatever your local port is)
  • Database name: your MariaDB database name
  • Database user name: your MariaDB database user name
  • Database user password: your MariaDB database user password

Connecting to a MariaDB Database over the Web

Your Opalstack service includes a web-based database administration tool called Adminer which is similar to phpMyAdmin.

To access Adminer:


Go to in your browser, replacing SERVERNAME with your Opalstack server name (for example "opal1" or "vps2").


Complete the login form as follows:

  • Server: MariaDB
  • Username: your MariaDB user name
  • Password: your MariaDB user password
  • Database: your MariaDB database name.

Click the Login button to log in to your database with the credentials you provided in step 2.