Install MariaDB

A short tutorial on how to install MariaDB (a MySQL alternative) on Raspberry Pi.

The initial installation of MariaDB uses the APT package manager so the below commands should work on all Linux distros that support APT, in this instance I am installing it onto a Raspberry Pi 2 running the standard Raspbian OS.

First of all it is always good practice to make sure that you have the latest versions of the packages available to you:

sudo apt update

Then to install MariaDB then run:

sudo apt install mariadb-server

If you are planning on using your SQL database with PHP then you will also need to to run:

sudo apt install php-mysql

It is advised (but optional) that you then run the following command and choose the relevant options, I personally accept the default options by pressing ‘Y’ to the prompts:

sudo mysql_secure_installation

Now that MariaDB is installed and configured, you will need to login to SQL:

sudo mysql -u root -p (enter your root password)

Then you can create a new database (I have highlighted in red which variables you need to change for your own needs)

CREATE DATABASE newdatabasename;

Substitute newdatabasename with your desired database name.

It is also best practice to create a new SQL user:

CREATE USER ‘newdbuser‘@’localhost’ IDENTIFIED BY ‘newdbuserpassword‘; 

Substitute ‘newdbuser‘ and ‘newdbuserpassword‘ with you own desired username and password respectively.

Then you need to give the newdbuser permissions on the newdatabasename database:

GRANT ALL PRIVILEGES ON newdatabasename.* TO ‘newdbuser‘@’localhost’;

Then finally to complete the setup run:

FLUSH PRIVILEGES;

Leave a Reply

Your email address will not be published. Required fields are marked *