# Storing Data with MariaDB

# Prerequisites

  • A firewall rule to accept traffic on TCP port 3306 has been added
  • If using a virtual machine, port 3306 is forwarded

# Install MariaDB

sudo apt update
sudo apt install -y mariadb-server

# Create a Database and a User

Log in as the root system user.

sudo mariadb

Create a database for your web application.

CREATE DATABASE mydatabase;

Create a user to represent your web application.

CREATE USER '[username]'@'%' IDENTIFIED BY '[password]';

Replace [username] and [password] with the actual credentials you want your web applications to use when they authenticate to the database.

Grant database privileges to this user.

GRANT ALL PRIVILEGES ON mydatabase.* TO '[username]'@'%';

Apply the privilege changes.

FLUSH PRIVILEGES;

Exit the MariaDB REPL.

EXIT;

# Allow Remote Connections

Edit /etc/mysql/my.cnf.

Add the following lines at the end of the file.

[mysqld]
bind-address = 0.0.0.0

Save and close the file.

Restart the database service.

sudo systemctl restart mariadb