MariaDB is a popular, open-source relational database management system (RDBMS) that is designed to be compatible with MySQL. It’s widely used for web applications and software development projects. In this guide, we’ll walk you through the steps to install and configure MariaDB on Ubuntu 22.04 and 24.04 LTS.
Why Choose MariaDB?
- High Performance: MariaDB is optimized for speed and efficiency, making it a great choice for demanding workloads.
- MySQL Compatibility: If you’re already using MySQL, switching to MariaDB is relatively easy.
- Large Community: MariaDB has a strong community of users and developers, providing ample support and resources.
- Open Source: You can customize and extend MariaDB to fit your specific needs.
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
Installation Steps:
Step 1. Update Your System:
Before installing MariaDB, ensure your Ubuntu system is up-to-date:
sudo apt update
Step 2. Install MariaDB:
Install MariaDB using the following command:
sudo apt install mariadb-server
Step 3. Secure the Installation:
Run the security script to enhance MariaDB’s security:
sudo mysql_secure_installation
This script will guide you through setting a root password, removing anonymous users, disallowing remote root login, and removing the test database.
Step 4. Verify Installation:
Start and enable the MariaDB service:
sudo systemctl start mariadb.service sudo systemctl enable mariadb.service
Step 5. Connecting to MariaDB
Use the following command to connect to MariaDB using the root user:
sudo mysql; #or sudo mysql -u root -p
Step 6. Creating Users and Databases
To create a new user and database, execute these SQL commands:
CREATE DATABASE your_database; CREATE USER 'your_user'@'localhost' IDENTIFIED BY "your_password"; GRANT ALL PRIVILEGES ON your_database.* TO 'your_user'@'localhost' IDENTIFIED BY 'your_password'; FLUSH PRIVILEGES;
That’s it! You have successfully installed and secured MariaDB on your Ubuntu. You can further refer to our available article on optimizing MySQL performance for additional guidance.