Skip to Content

Setting up the database

A step-by-step guide to setting up a MariaDB database for a FiveM server, with an optional phpMyAdmin install.

Install MariaDB

Install the MariaDB server

Install the mariadb-server package with the package manager.

sudo apt update
sudo apt install mariadb-server -y

Secure the installation

Run the mysql_secure_installation script.

sudo mysql_secure_installation

Answer Yes (Y) to every question in the wizard.

Create the database and user

Log in to MariaDB

Log in to the MariaDB console with the password you set in the previous step.

sudo mysql -u root -p

Create the database

Create a new database for your FiveM server. Replace database_name with a name of your choice.

CREATE DATABASE database_name;

Create the user

Create a new user with a password. Replace username and strong_password with your own values.

CREATE USER 'username'@'localhost' IDENTIFIED BY 'strong_password';

Grant privileges

Give the new user full privileges on the database you created.

GRANT ALL PRIVILEGES ON database_name.* TO 'username'@'localhost';

Apply the changes and exit

Reload the privileges and leave the MariaDB console.

FLUSH PRIVILEGES;
EXIT;

Configure the FiveM server

Now tell your FiveM server how to connect to the new database. Open your FiveM server's server.cfg file and add the line below, with your own values.

set mysql_connection_string "mysql://username:strong_password@localhost/database_name?charset=utf8mb4"

Install phpMyAdmin (optional)

phpMyAdmin is a popular web tool for managing databases. It is optional, but it can make your work much easier.

Install phpMyAdmin and its dependencies

Install phpmyadmin and the PHP extensions it needs.

sudo apt install phpmyadmin php-mbstring php-zip php-gd php-json php-curl -y

During the installation you are asked to choose a web server. If you are not sure, choose apache2 (even if you don't use it) and press Enter. Then choose Yes to configure the phpMyAdmin database with dbconfig-common.

Configure the web server

Create a symbolic link to the phpMyAdmin installation directory.

sudo ln -s /usr/share/phpmyadmin /var/www/html/phpmyadmin

Then add the location below to your server's Nginx configuration so PHP is handled correctly.

location /phpmyadmin {
    root /var/www/html;
    index index.php;

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php8.4-fpm.sock; # Make sure the PHP version is correct
    }
}

Open phpMyAdmin

phpMyAdmin is now available in your browser at http://<YOUR_VPS_IP>/phpmyadmin. Log in with the database user you created earlier.