Cart

    Sorry, we could not find any results for your search querry.

    Installing a MariaDB database server in Ubuntu or Debian

     

    MariaDB is an open source database server derived from MySQL. Together with Apache and PHP, MariaDB forms the so-called LAMP stack (with MariaDB replacing MySQL) that is used to host dynamic websites (e.g. WordPress). This guide shows you how to install MariaDB on a VPS running Ubuntu 24.04 or Debian. We also explain several command-line instructions for managing MariaDB.

    Execute the following steps as the root user, or use sudo before each command.


     

    Installing and Configuring MariaDB

     

    Step 1

    Connect to your VPS via SSH or use the VPS console. First, update your system:

    sudo apt -y update
    sudo apt -y upgrade

    It is recommended to reboot your VPS after the update. After rebooting, run the update and upgrade commands again to ensure that all packages are current.


     

    Step 2

    Fetch and execute the MariaDB repository setup script. This will configure your VPS to install packages from the MariaDB repository for the latest MariaDB version (here exemplified by MariaDB 11.8; replace with your desired version if needed):

    curl -LsS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash -s -- --mariadb-server-version=11.8

    Alternatively, if you do not want to specify a version and wish to add both the general repository as well as additional repositories (e.g. for MariaDB MaxScale and MariaDB Tools), you can omit the version parameter:

    curl -sS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash

     

    Step 3

    Update your package list so that the new repository takes effect, then install MariaDB server and client:

    sudo apt -y update
    sudo apt -y install mariadb-server mariadb-client

    During the installation, you will be prompted to set a password. For security reasons, choose a password that is not used for other services on your VPS.


     

    Step 4

    Before using MariaDB, secure your installation by running:

    sudo mysql_secure_installation

    Carefully follow the prompts to secure your server. A suggested configuration is as follows:

    • When prompted for the current root password (press Enter if none has been set): press Enter.
    • You may be asked about switching to unix_socket authentication; if your root account is already protected, respond with n.
    • When asked to change the root password, answer with n (if you already set it during installation).
    • Remove anonymous users: type y.
    • Disallow remote root logins: type y.
    • Remove the test database and access to it: type y.
    • Reload the privilege tables: type y.

    Once completed, your MariaDB installation is secured.


     

    Firewall and External Connections

     

    By default, SQL port 3306 is not opened in your firewall. In most cases, you do not need to open this port – for example, a typical WordPress installation communicates with MariaDB via localhost. However, if your use-case requires external access to the SQL port (for another server or remote management), follow these instructions.

     

    Configuring the Firewall

    If you are using UFW (the default in Ubuntu), open port 3306 only for specific sources rather than for the entire Internet. For example, to allow access only from a particular IP address, run:

    sudo ufw allow from 123.123.123.123 to any port 3306 proto tcp

    Replace 123.123.123.123 with the IP address you wish to grant access. If you really need to allow connections from anywhere (not recommended for production), you can use:

    sudo ufw allow 3306/tcp

     

    Making MariaDB Externally Reachable

    By default, MariaDB is bound to localhost (127.0.0.1) and is therefore not accessible externally. To allow external connections, change the bind address. Open the configuration file:

    sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf

    Locate the line:

    bind-address = 127.0.0.1

    and replace it with:

    bind-address = YOUR_VPS_IP_ADDRESS

    Replace YOUR_VPS_IP_ADDRESS with the IP address on which you wish MariaDB to listen. Save the file and then restart MariaDB:

    sudo systemctl restart mariadb

     

    Managing MariaDB

     

    There are two common approaches to managing MariaDB: via the command line or using a web-based tool such as phpMyAdmin.

    • phpMyAdmin: For installation and usage instructions, please refer to the dedicated phpMyAdmin guide.
    • Command-Line: This guide covers managing MariaDB through the SQL shell available on the command line.

    For PHP-based database management, consult the documentation on w3schools.com.


     

    Your MariaDB server is properly installed and configured. Do you need to set up redundancy for your MariaDB server? Make sure to check out our redundancy series.

    Need help?

    Receive personal support from our supporters

    Contact us