How to Install MariaDB Server on Raspberry Pi with Debian 10 Buster

1892
Share:
how-to-install-mariadb-server-on-debian-10-buster

I use Raspberry Pi as my personal web development server. It runs LEMP stack: Linux (Ubuntu/CentOS), Nginx web server, MariaDB database, and PHP 7/8. Whenever I need to change the OS I just to switch the microSD card.

This article I'll show you how to install MariaDB to a Raspberry Pi device.

Note: I'm using Debian 10 Buster, not Raspbian/Raspberry Pi OS. The commands are still valid for Raspbian/Raspberry Pi OS.

MariaDB 10.3 Installation on Raspberry Pi

Please note that personally I don’t recommend running a database server (MariaDB in this case) on a Raspberry Pi unless you have a high-quality and high-speed USB flash drive MicroSd card from which you run the OS.

Update packages on Raspberry

For Debian users, updating packages is incredibly easy task. It involves typing two very simple commands into terminal. It is good to remember the two commands that are shown below as they will quickly become some of your most used Linux commands.

$ sudo apt update
$ sudo apt upgrade

The first of these commands (sudo apt update) makes a call to the Advanced Packaging Tool (apt) to update the package list, this is highly important as the install and upgrade commands only search the pre-grabbed package list and don't make any attempts to update it themselves.

The update command works this by searching the /etc/apt/sources.list file, and then polling all the websites in the list for all available packages creating a list of their download location and their current version.

The default location that Debian uses for its packages can be found on Debian's mirror director, this mirror director is designed to automatically direct you to the closest download provider.

Failing to run the update command before running install or upgrade could also cause you to run into download errors especially when packages are moved around on the mirror server.

The second command (sudo apt upgrade) again utilizes the Advanced Packaging Tool (apt), but this time it uses it to check all currently installed packages against the package list, if there is a version miss-match for any it will attempt to update it by downloading the new version from the link in the list. The upgrade tool will never remove a package.

Once all the updates are installed, we’re ready to install MariaDB server.

MariaDB installation process

In this part of the article we will be exploring on how to install MariaDB server on Raspberry Pi. First, issue this command:

$ sudo apt install mariadb-server

and press Enter. Note that on Raspbian, MariaDB is being used as MySQL drop-in replacement. This means that all MySQL command should be available on MariaDB.

$ sudo apt-get install mariadb-server
Reading package lists... Done
Building dependency tree      
Reading state information... Done
The following additional packages will be installed:
  galera-3 gawk libconfig-inifiles-perl libdbi-perl libreadline5 libsnappy1v5 mariadb-client-10.3 mariadb-client-core-10.3
mariadb-server-10.3 mariadb-server-core-10.3 socat
Suggested packages:
  gawk-doc libclone-perl libmldbm-perl libnet-daemon-perl libsql-statement-perl mailx mariadb-test tinyca
The following NEW packages will be installed:
  galera-3 gawk libconfig-inifiles-perl libdbi-perl libreadline5 libsnappy1v5 mariadb-client-10.3 mariadb-client-core-10.3
mariadb-server mariadb-server-10.3 mariadb-server-core-10.3 socat
0 upgraded, 12 newly installed, 0 to remove and 0 not upgraded.
Need to get 18.8 MB of archives.
After this operation, 163 MB of additional disk space will be used.
Do you want to continue? [Y/n] y

If you notice on the installation screen, the installation process will also installs its client. This client will allow you to connect to your server from the command line which is always handy to do. After a short while, you will see this something like this:

Created symlink /etc/systemd/system/mysql.service → /lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/mysqld.service → /lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/multi-user.target.wants/mariadb.service → /lib/systemd/system/mariadb.service.
Setting up mariadb-server (1:10.3.27-0+deb10u1) ...
Processing triggers for systemd (241-7~deb10u5) ...
Processing triggers for man-db (2.8.5-2) ...
Processing triggers for libc-bin (2.28-10) ...

and you have your shell back ($). It means the installation is almost finished. Let's proceed to next steps.

Setting MariaDB root password

Next steps is database configuration, which the crucial thing is setting root database password. On your terminal, type this command:

$ sudo mysql_secure_installation 

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):

Just press Enter because we just installed MariaDB server. Next step is:

OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n]

Press Y and enter your password twice. The passwords aren't visible on the screen. This is normal behavior.

Set root password? [Y/n] Y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n]

Press Y to remove anonymous users.

Remove anonymous users? [Y/n] Y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n]

Press Y to disallow root login remotely.

Disallow root login remotely? [Y/n] Y
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n]

Press Y to remove test database and user

Remove test database and access to it? [Y/n] Y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n]

Press Y to reload privilege tables. This is the last step of MariaDB interactive installation process.

Reload privilege tables now? [Y/n] Y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

That's it. Installation process is complete. Next step we will try to connect to our newly installed server.

Connect to Database

Here we are, the moment of truth. Now let's try connecting to our server using the client installed at the same time as the server. Type the following command:

$ mysql -u root -p

The -p parameter means it will ask for password. Enter your password and if everything is installed correctly, you will see:

$ mysql -u root -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 57
Server version: 10.3.27-MariaDB-0+deb10u1 Debian 10

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

Congratulations, your MariaDB server is installed successfully. Have fun!

Access Denied Error

If you tried to login with correct credentials but it keeps saying like this:

ERROR 1698 (28000): Access denied for user 'root'@'localhost'

You can try to disable MySQL from trying to authenticate root user using plugin:

$ sudo mysql -u root

[mysql] use mysql;
[mysql] update user set plugin='' where User='root';
[mysql] flush privileges;
[mysql] \q

Final Words

I hope that you now know how to install MariaDB 10.3 on Raspberry Pi. If you run into any issues or have any feedback feel free to drop a comment below.

Tags Linux
Share:

0 comment

Leave a reply

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