How to install MariaDB on Raspbian and the Raspberry Pi
In the last tutorial, we showed you how to replace Apache by Nginx for your Raspbian system, in order to get a faster and less RAM-consuming web server.
Today, we will continue to optimize our web server on the Raspberry Pi by interesting us to the database. So we’ll see how to install MariaDB on the Raspberry Pi.
What is MariaDB?
Before we go to the installation, let’s talk a little more about MariaDB, what it is and what it serves.
Until now, we talked about MySQL, which is probably the most used DBMS (at least 56% market share on free technologies). But MySQL is not alone in the world of free DBMS and all its competitors, the most serious is undoubtedly MariaDB, whether by its market shares (18%), by its functionalities, very similar to those of MySQL , Or by its perfect compatibility with MySQL. Not surprisingly, since the creator of MariaDB (Michael Widenius) is also the creator of MySQL.
Why did Michael Widenius create MariaDB instead of continuing to improve MySQL?
To find the answer to this question, you have to make a small jump back in the history of MySQL.
In 1995 Michael Widenius founded MySQL AB, an open source software company, and soon became a major player in the database industry.
In 2008, MySQL was bought for $ 1 billion by Sun Microsystems, another major player in the field of open source software.
In 2009, Sun Microsystems was acquired by Oracle, and MySQL with it.
It is at this moment that everything will change. There were real concerns about Oracle’s willingness to maintain and evolve MySQL in an open source and free way, with Oracle already offering a competing, paying, proprietary solution for large companies, the well-known Oracle Database.
In 2009, Michael Widenius leaves Sun on his redemption, get back the source code of MySQL (free software) and launches a petition to pressure Oracle to continue to develop MySQL.
In order to ensure that the code of MySQL remains free, and that it does not disappear, Michael Widenius will then create a new DBMS, fork of MySQL (a fork is a software created from the source code of another).
He will name this DBMS after his second daughter name, Maria, as he had done with MySQL and his first daughter, My.
A foundation will then be create, the MariaDB Foundation, to ensure the governance of the project.
Since then, MariaDB develops more and more every day, continuing to ensure compatibility with MySQL and improving it.
Why use MariaDB on the Raspberry Pi
Eventually, MySQL always develops, and is still free, so why install MariaDB instead of MySQL on the Raspberry Pi?
First of all, because MySQL is distributed by Oracle, and Oracle is not very well seen in the world of free software, often preferring a proprietary logic, which is both stupid and wrong! Then, because MySQL may not remain open-source for a very long time, it is already dual-licensed, free and proprietary. Also, because MariaDB is 100% compatible with MySQL, and so there is no reason not to. Finally, and this is probably what will interest you most, for performance issues.
If MariaDB is increasingly used, it is not just because it is more open source than MySQL, but mainly because it is more efficient.
Indeed, benefiting from a large community of developers, and the experience of its creator, MariaDB presents performances superior to MySQL, while being perfectly compatible with this one. This means that to improve your site, simply install MariaDB instead of MySQL, and you will not even need to change the code of your website and applications!
MariaDB has a real performance improvement compared to MySQL, especially on complex queries. This is due in part to the use of the Aria engine rather than the InnoDB engine and the optimization efforts at the heart of the MariaDB project (you can find comparisons between MariaDB and MySQL on this point at this address).
This is due in part to the use of the Aria engine rather than the InnoDB engine and the optimization efforts at the heart of the MariaDB project (you can find comparisons between MariaDB and MySQL on this point at this address).
To give you an idea of this difference, here is a quick benchmark comparing MariaDB and MySQL.
And unlike Nginx and Apache, there is no real counterpart to the advantages of MariaDB over MySQL. You will have nothing else to do but disable MySQL and install MariaDB.
MariaDB is therefore a perfect choice for a Raspberry Pi using Raspbian, since the RAM resources are limited, with only 1 GB for the Raspberry Pi 3 (by the way, if you do not already have it, you can find it here on Amazon) and only 512MB for the Raspberry Pi Zero (which you can find there).
Install MariaDB on Raspbian
With the new version of Raspbian, MariaDB is now present in the official repositories, which until now was not the case!
To install it, nothing more simple therefore, you just need to run the following command:
sudo apt-get install mariadb-server
If you already have MySQL installed, it is likely that the package manager notifies you of a conflict and asks if it needs to uninstall MySQL. In this case, answer yes.
During the installation, MariaDB will configure itself. It’s up to you to provide the administrator account for the database.
This done, it should ask you if you are sure to want to go under MariaDB. Again, answer yes.
Once the installation is complete, you will be able to access MariaDB as you did with MySQL, simply with the following command:
mysql -u user -p
Here, you now know how to install MariaDB on the Raspberry Pi.
As you may have seen, during this tutorial we have often referred to Nginx, and it’s not for nothing. Indeed, the couple Nginx / MariaDB is more or less the modern equivalent of the pair Apache / MySQL. We strongly encourage you to use Nginx with MariaDB for an ever faster web server!
Alternatively, you can also check out our tutorials around the accessories of the Raspberry Pi or about how to create a media center with the Raspberry Pi!