MariaDB is an open-source database management system developed from the MySQL codebase, and it’s considered an excellent alternative to MySQL due to its compatibility and better performance. In this guide, we’ll go through three simple commands to install the latest version of MariaDB on Ubuntu 22.04, or Debian.
Uninstall Existing MySQL (Optional)
If you have another MySQL database system installed, we recommend uninstalling it first to avoid potential conflicts. Backup any existing databases before proceeding with these commands:
sudo service mysql stop
sudo apt purge 'mysql*' mysql-server mysql-client mysql-common mysql-server-core-* mysql-client-core-*
sudo apt remove 'mysql*' && sudo apt autoremove && sudo apt autoclean
sudo rm -rf /etc/mysql /var/lib/mysql /var/log/mysql
Install MariaDB with 3 Commands
On Ubuntu 22.04 and above, and Debian 10 and above, the MariaDB repository is already included. So, you only need to run the following three commands to install the latest version:
sudo apt update
sudo apt install mariadb-server
sudo mysql_secure_installation
The first command updates package lists, the second installs the MariaDB server, and the third runs a security script to harden your installation.
Configure MariaDB Security
The mysql_secure_installation
script will prompt you to set up essential security settings like the root password, remove anonymous users, and disable remote root login.
sudo mysql_secure_installation
Log in to MariaDB
After installation, you can log in to the MariaDB shell with sudo mariadb
or sudo mysql
.
Start MariaDB Automatically (Ubuntu 20.04)
Note: On Ubuntu 20.04, after completing all the above steps, you may need to run a command to enable MariaDB to start automatically on the system.
sudo systemctl start mariadb.service
sudo systemctl enable mariadb.service
That’s it! You have successfully installed and secured MariaDB on your Ubuntu or Debian system. You can further refer to our available article on optimizing MySQL performance for additional guidance.