How to easily install MariaDB on Ubuntu 22.04 | 20.04 and Debian using just three commands. MariaDB is a free database management system developed from the open-source code of MySQL, and it is considered a perfect alternative to MySQL due to its compatibility and better performance.
Step by step: install MariaDB on Ubuntu 22.04, 20.04 and Debian
Unlike other database management systems, when installing MySQL, you need to add a repository. However, for operating systems Ubuntu 22.04 and above and Debian 10 and above, the repository is already available. Therefore, you only need to run the three commands below to install the latest edition of MariaDB in the Ubuntu session.
sudo apt update sudo apt install mariadb-server sudo mysql_secure_installation
With the commands above, it includes “sudo apt update” to update the system packages. In fact, it is not necessary, but it’s a common practice whenever installing any application or tool to run the “update” command for the package.
Note before installing MariaDB on Debian or Ubuntu 22.04 | 20.04
Advice: If you are using another MySQL database management system, it is recommended to delete it before installing MariaDB to avoid potential errors. The commands below will assist you in completely removing MySQL from the system (Note: remember to back up any databases before proceeding).
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
After running the command “sudo apt install mariadb-server’” to install MariaDB on Ubuntu 22.04 or Debian Linux, it won’t prompt you to set a password or make any other configuration changes. Due to the default configuration, your MariaDB installation may be insecure. To enhance security, you can use the script provided by the mariadb-server package. This script helps restrict access to the server and remove unused accounts.
How to Configure and Secure MariaDB on Ubuntu and Debian
The next step is to run the command for security. This command will change some of the less secure default options for things like root and remote user credentials.
To configure and secure MariaDB, run the command below and the accompanying prompts. This command for MariaDB will be different from other MySQL systems. So please enter the keys correctly to avoid incorrect configuration and fix the error.
After installing MariaDB on Ubuntu 22.04, you can log in and use MariaDB with the commands
sudo mariadb or
sudo mysql. Additional documentation on using MySQL or config and optimization MySQL is available for further reference.
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
Above is the simplest way to install MariaDB on Ubuntu 22.04 | 20.04 or Debian with 3 steps, you can also refer to the instructions directly from the MariaDB homepage .