MariaDB is a powerful, open-source relational database management system that serves as a popular drop-in replacement for MySQL. It’s known for its robust performance, reliability, and enhanced security features, making it an excellent choice for a wide range of applications, from web development to enterprise-level data management. This Tutorial will guide you through the process of installing MariaDB on your Ubuntu 24.04 server, securing it, and setting up a Basic database and user.
Before you begin, ensure you have an Ubuntu 24.04 server with a non-root user configured with sudo privileges and an active internet connection.
Step 1: Update System Packages
It’s always a good practice to update your system’s package list and upgrade any existing packages to their latest versions before installing new software. Open your terminal and run the following commands:
sudo apt update
sudo apt upgrade -y
Step 2: Install MariaDB Server
Ubuntu 24.04’s default repositories include the MariaDB server package. You can install it with a single command:
sudo apt install mariadb-server -y
Once the installation is complete, the MariaDB service will automatically start. You can verify its status using:
sudo systemctl status mariadb
You should see output indicating that the service is ‘active (running)’. Press q to exit the status view.
Step 3: Secure MariaDB Installation
MariaDB comes with a security script that helps you improve the security of your database server. This script prompts you to set a root password, remove anonymous users, disallow remote root login, and remove the test database.
sudo mysql_secure_installation
Follow the prompts:
- Enter current password for root (enter for none): Press Enter, as there’s no password set for the root user initially.
- Set root password? [Y/n]: Type
Yand press Enter, then set a strong password for the MariaDB root user. - Remove anonymous users? [Y/n]: Type
Yand press Enter. - Disallow root login remotely? [Y/n]: Type
Yand press Enter. - Remove test database and access to it? [Y/n]: Type
Yand press Enter. - Reload privilege tables now? [Y/n]: Type
Yand press Enter.
Step 4: Create a New User and Database (Optional but Recommended)
It’s best practice to create dedicated users and databases for your applications instead of using the root user. First, log in to the MariaDB shell as the root user:
sudo mariadb
Now, execute the following SQL commands. Replace your_database_name, your_username, and your_password with your desired values:
CREATE DATABASE your_database_name;
CREATE USER 'your_username'@'localhost' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON your_database_name.* TO 'your_username'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;
EXIT;
These commands create a new database, a new user, grant that user full privileges on the new database, and then reload the privilege tables.
Step 5: Test MariaDB Installation
You can test your new user by logging in with the credentials you just created:
mariadb -u your_username -p
Enter your_password when prompted. If successful, you’ll enter the MariaDB shell. You can then verify access to your database:
SHOW DATABASES;
USE your_database_name;
Type exit; to leave the MariaDB shell.
With MariaDB successfully installed and secured on your Ubuntu 24.04 server, you’re now ready to integrate it with your applications. This robust database system provides a solid foundation for managing your data efficiently and securely.
