How to Install MariaDB on Raspberry Pi? (MySQL Server)

MariaDB is one of the most common service used on Raspberry Pi
But I know that some of you have problems installing and configuring it properly
So, I’m writing a specific tutorial on how to install it

How to install MariaDB on a Raspberry Pi?
MariaDB is available in the Raspbian repository, so you can install it with: “apt install mariadb-server”
Then you’ll need to create a new user and a database
And finally you can configure the server in the /etc/mysql folder

That’s it for the main steps
In the following of this tutorial, I will guide you through each step so you’ll know exactly what to do

By the way, if you don’t have a budget to afford a course for now (if you just got your Raspberry Pi stuff, I completely understand), you can join Skillshare for a free 14-day trial. It includes courses from the best teachers in many categories, including IT (Linux, programming, …) and Raspberry Pi. I highly recommend getting this offer now so that you can already learn a bunch of things in the next fortnight. I’m a fan of their services personally 🙂

What is MariaDB?

Get My Cheat Sheet!
Grab your free PDF file with all the commands you need to know on Raspberry Pi!

Let’s start by a short explanation of what is MariaDB for those who may need this

What is a database?

The name is almost explicit
But if you are starting on MySQL, imagine a database as file where you will store any data you need to keep
For example, this website use a database to store the posts content, the comments or the website configuration

I often explain a database as a folder on your computer, with many excel files in it
The folder is the database, each Excel file is a table, and they contain one column for each data to store

What is MariaDB?

Raspberry Pi Bootcamp
Sale: 10% off today.
Take it to the next level.
I'm here to help you get started on Raspberry Pi.
Learn all the skills you need in the correct order.

MariaDB is the service that will host the database
As Apache is used to host a web server, MariaDB is used to store data in databases

It’s a free service, available on any Linux distribution
MariaDB is a young project, started in 2009 and now supported by major companies like Google and Alibaba

It’s not yet one of the most popular database engine (0.58% market share according to Datanyze), but it’s growing fast
Big companies like Google, Mozilla and Wikipedia are using it

Difference between MariaDB and MySQL?

MariaDB is a fork of MySQL (= they create it from a copy of the MySQL source code)
So, for now there is almost no difference

MariaDB has been created following the MySQL acquisition by Oracle in 2009
So, it’s highly compatible with MySQL
Most of the projects will work on MariaDB without requiring any changes

How to install MariaDB on Raspbian?

Now that you have more information about what is MariaDB, you can try to install it by reading the following instructions

Server instalation

As said in the introduction, MariaDB is available in the Raspbian repository, so the installation is straightforward:

  • As always, start by updating your system:
    sudo apt update
    sudo apt upgrade
  • Then you can install MariaDB with this command:
    sudo apt install mariadb-server
  • Type “Y” and Enter to continue
    After a few seconds, the installation process is complete and MariaDB is almost ready to use

If you have noticed it, the installation of MariaDB has also installed the MariaDB client
This will allow you to connect from the command line with: mysql

But by default, there is no account available to connect
That’s why we need to create root access first

Root access

Here is how to define the password for the root user and start to use MariaDB:

  • Enter this command:
    sudo mysql_secure_installation
  • A message like this appears:
  • Press enter to continue (no password by default)
  • Then type “Y” to set a new password, and enter the password of your choice
  • Now, press “Y” three times to:
    • Remove anonymous users
    • Disallow root login remotely
    • Remove the test database
  • And finally, press “Y” again to reload the privileges

That’s it, this time MariaDB is ready to use with to root login

Connect with root

You can now use the mysql command for your first connection:

Master your Raspberry Pi in 30 days
Sale: 10% off today.
Download the eBook.
Uncover the secrets of the Raspberry Pi in a 30 days challenge.
Learn useful Linux skills and practice multiples projects.

sudo mysql -uroot -p
Then enter the password you have defined previously
And that’s it, you are connected to the MySQL server

Once you are connected, you can use all the MySQL queries like these:

  • USE <database>;
  • SELECT * FROM <table>;

You’ll check the syntax and all the information on the official documentation

Create a new MariaDB user

As on your system, it’s not recommended using the root user for any application
Keep it for you, for administration and debugging on a local usage
But for any other applications, you will probably create new users, with access to only one specific database

Create a new user on MariaDB

Here is how to do this

  • Connect to the MySQL command line:
    sudo mysql -uroot -p
  • Create a new database:
    CREATE DATABASE <dbname>;
    In this step and the following, replace all variables between <…> by the name you want to use
  • Now, create the new user:
    CREATE USER '<username>'@'localhost' IDENTIFIED BY '<password>';
  • Then, allow this new user to do anything on the database we just created:
    GRANT ALL PRIVILEGES ON <dbname>.* TO '<username>'@'localhost';
  • Finally, reload the permissions with:

Test the connection

You can now check that everything works fine with:
sudo mysql -u<username> -p
And use the password you just created

That’s it, you can now do everything you want on the new database
You can for example use this to host a website on your Raspberry Pi, or even to host apps like NextCloud or WordPress at home

Further configuration

You can do most of the MySQL configuration in the command line, but it’s not always easy if you don’t know the MySQL language
So, I’ll show you here two ways to configure your server


As with many services, you’ll find a configuration file in the /etc folder
It’s the first way to change the configuration

Here are the files you’ll find under /etc/mysql:

├── conf.d
│   ├── mysql.cnf
│   └── mysqldump.cnf
├── debian.cnf
├── debian-start
├── mariadb.cnf
├── mariadb.conf.d
│   ├── 50-client.cnf
│   ├── 50-mysql-clients.cnf
│   ├── 50-mysqld_safe.cnf
│   └── 50-server.cnf
├── my.cnf -> /etc/alternatives/my.cnf
└── my.cnf.fallback
Master Python on Raspberry Pi
Sale: 10% off today.
Get the eBook.
Do more with your Raspberry Pi, learn the useful concepts and take the shortcuts.
You miss half of the fun of using a Raspberry Pi if you don’t know anything about Python.

As you use MariaDB, you need to edit the files under mariadb.conf.d

  • For the server configuration, open the 50-server.cnf file like this:
    sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf
  • In this file you can find many configuration options
    Each line uses the same format:
    option = value
    Lines starting with a # are commented, you need to remove this character to change the value
  • For example, you can change the bind-address to allow remote connections, or the datadir to move the databases to another directory (on a USB drive for example)

You can find all the information about this file on the MariaDB website


Even if the configuration file is mandatory to change the configuration, you’ll not change it everyday
But one thing that you’ll do more often is to create users, databases and table
Or just reading the data in the tables

phpmyadmin interface

You can install PhpMyAdmin to avoid using the MySQL console for each operation
PhpMyAdmin is a free web interface that you can install on your Raspberry Pi to do all the basic operations on your database

You can follow the step by step tutorial on this post to install it
This tutorial installs Apache and PHP before, but the PhpMyAdmin installation will add and configure them automatically

Support me: Join the community on Patreon to show your support, get behind-the-scenes content and other awesome perks!


Get My Cheat Sheet!
Grab your free PDF file with all the commands you need to know on Raspberry Pi!

That’s it, you now know how to install MariaDB on Raspberry Pi, and also how to configure and manage it on a daily basis

If you need more information on this topic, let me know in the comments, so I can answer your questions and also write other posts on this subject
And as usual, thanks to share this post in your favorite social network if it was useful for you!

Raspberry Pi Resources

Not sure where to start?
Understand everything about the Raspberry Pi, stop searching for help all the time, and finally enjoy completing your projects.
Watch the Raspberry Pi Bootcamp course now.

Master your Raspberry Pi in 30 days
Don’t want the basic stuff only? If you are looking for the best tips to become an expert on Raspberry Pi, this book is for you. Learn useful Linux skills and practice multiple projects with step-by-step guides.
Download the e-book.

VIP Community
If you just want to hang out with me and show your support, you can also join the Patreon community. I share behind-the-scenes content there and give you early access to my content. You’ll also get a shoutout when you join.
More details here.

Need help building something with Python?
Create, understand and improve any Python script for your Raspberry Pi.
Learn the essentials, step-by-step, without losing time understanding useless concepts.
Get the e-book now.

You can also find all my recommendations for tools and hardware on this page.

This tutorial doesn't work anymore? Report the issue here, so that I can update it!

0 0 votes
Article Rating

Patrick Fromaget

I'm the lead author and owner of My goal is to help you with your Raspberry Pi problems using detailed guides and tutorials. In real life, I'm a Linux system administrator with a web developer experience.

Notify of
Inline Feedbacks
View all comments

Recent Posts

Master your Raspberry Pi - 10% off