How to Install MariaDB on Debian 12?
MariaDB is an open-source relational database management system (RDBMS) that is driven by the community and used in a variety of applications, ranging from web servers to content management systems, to data analysis tools. It was initially developed by the MySQL team, and MariaDB is completely compatible with MySQL and can be used as a flawless drop-in replacement. It provides users with additional features, stability, and performance enhancements under the GPL license. Focused on reliability, scalability, and security, MariaDB is a developer and organization favorite that needs a high-performance, reliable database solution.
On Debian 12, MariaDB is a great option due to the simplicity of installation, the large community base, and ease of integration with the operating system. The combination of Debian stability and MariaDB optimizations makes the pair a great option for production.
Whether you’re implementing a database for a small application or installing a big system, MariaDB provides you with the utilities and features you need, including high availability, complex query support, and transaction handling. The tutorial will guide you through the process of installing MariaDB on Debian 12 and securing it to run optimally for your specific application.
Prerequisites
- Before proceeding, ensure you have:
- A Debian 12 (Bookworm) system.
- Root or sudo privileges on the system.
Step 1: Update the System
Start by updating your system’s package index and upgrading existing packages to their latest versions:
sudo apt update && sudo apt upgrade -y
Step 2: Install MariaDB Server
MariaDB is included in Debian 12’s default repositories. To install it, execute:
sudo apt install mariadb-server -y
Step 3: Verify Installation
After installation, verify that MariaDB is running:
sudo systemctl status mariadb
Expected output:
mariadb.service - MariaDB 10.11.6 database server Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; preset: enabled) Active: active (running) since [date]; [time] ago Docs: man:mariadbd(8) https://mariadb.com/kb/en/library/systemd/ Process: [PID] ExecStartPre=/usr/bin/install -m 755 -o mysql -g root -d /var/run/mysqld (code=exited, status=0/SUCCESS) Main PID: [PID] (mariadbd) Status: "Taking your SQL requests now..." Tasks: [number] (limit: [limit]) Memory: [memory]M CPU: [cpu]ms CGroup: /system.slice/mariadb.service └─[PID] /usr/sbin/mariadbd
This output confirms that the MariaDB service is active and running.
Step 4: Secure the MariaDB Installation
It’s essential to secure your MariaDB installation by removing insecure defaults and setting up proper authentication. MariaDB provides a script to assist with this:
sudo mysql_secure_installation
You’ll be prompted to configure various settings:
Enter current password for root (enter for none): Press Enter (since no password is set by default).
Switch to unix_socket authentication [Y/n]: Press Y and Enter to enable it, enhancing security by allowing root login only from the local machine.
Change the root password? [Y/n]: Press Y and Enter to set a new root password when prompted.
Remove anonymous users? [Y/n]: Press Y and Enter to eliminate anonymous user accounts.
Disallow root login remotely? [Y/n]: Press Y and Enter to prevent root login from remote locations.
Remove test database and access to it? [Y/n]: Press Y and Enter to delete the test database, which is unnecessary in a production environment.
Reload privilege tables now? [Y/n]: Press Y and Enter to apply all changes.
After completing these steps, the script will confirm that the changes have been applied.
Step 5: Access the MariaDB Console
To interact with your MariaDB server, access the MariaDB monitor as the root user:
sudo mariadb -u root -p
Enter the root password you set during the secure installation when prompted.
Step 6: Create a New Database and User
Within the MariaDB console, you can create a new database and user:
–Create a new database
CREATE DATABASE example_db;
–Create a new user with a strong password
CREATE USER 'example_user'@'localhost' IDENTIFIED BY 'StrongPassword!2025';
–Grant all privileges on the new database to the new user
GRANT ALL PRIVILEGES ON example_db.* TO 'example_user'@'localhost';
–Apply the changes
FLUSH PRIVILEGES;
Replace ‘StrongPassword!2025’ with a secure password of your choice.
Step 7: Create a Sample Table and Insert Data
Still within the MariaDB console, switch to the new database and create a sample table:
–Switch to the new database
USE example_db;
–Create a sample table
CREATE TABLE products ( id INT AUTO_INCREMENT PRIMARY KEY, product_name VARCHAR(100) NOT NULL, unit_price DECIMAL(10, 2) NOT NULL );
–Insert sample data into the table
INSERT INTO products (product_name, unit_price) VALUES ('Sample Product 1', 19.99), ('Sample Product 2', 29.99);
–Retrieve and display the data
SELECT * FROM products; Expected output: +----+---------------------+------------+ | id | product_name | unit_price | +----+---------------------+------------+ | 1 | Sample Product 1 | 19.99 | | 2 | Sample Product 2 | 29.99 | +----+---------------------+------------+
This confirms that the table has been created and populated successfully.
Step 8: Exit the MariaDB Console
After completing your tasks, exit the MariaDB console:
EXIT;
Conclusion
In short, MariaDB installation on Debian 12 is an easy task which allows you to take full advantage of the system’s robust database features. Following the instructions of this tutorial, you have learned how to install the MariaDB server, make it secure, and create databases and users for your applications. With ACID-compliant transactions, advanced indexing, and optimization, MariaDB is an ideal database solution for any application, from a basic web application to a complex data-driven service.
Once you’ve installed MariaDB, you’ll be able to store and manage your data efficiently, and your applications will be reliable and consistent. Whether it’s a new project or keeping an existing one running, MariaDB is flexible and speedy enough to perform a range of operations. Having completed the installation, you can now proceed and incorporate MariaDB into your server environment, knowing that it will be secure and efficient for your database management requirements.