Install MariaDB on Debian 12
How to Install MariaDB on Debian 12: A Complete Guide
MariaDB is a popular, open-source relational database management system that is widely used as a drop-in replacement for MySQL. It is known for its speed, reliability, and active development community. In this tutorial, we will guide you step-by-step on how to install MariaDB on Debian 12.
Prerequisites
Before you begin, ensure you have:
A system running Debian 12 (Bookworm)
A user account with sudo privileges
Basic terminal knowledge
Step 1: Update System Packages
Start by updating your system’s package index to ensure all available packages are up to date.
bash
CopyEdit
sudo apt update && sudo apt upgrade -y
Step 2: Install MariaDB Server
MariaDB is included in the default Debian repositories. You can install it using the following command:
bash
CopyEdit
sudo apt install mariadb-server -y
Step 3: Start and Enable MariaDB Service
Once installed, start the MariaDB service and enable it to automatically start on boot.
bash
CopyEdit
sudo systemctl start mariadb sudo systemctl enable mariadb
You can verify that MariaDB is running by checking its status:
bash
CopyEdit
sudo systemctl status mariadb
Step 4: Secure MariaDB Installation
MariaDB comes with a security script that helps you improve the security of your installation.
Run the following command:
bash
CopyEdit
sudo mysql_secure_installation
The script will prompt you to:
Set a root password (optional in Debian, as root login via socket is default)
Remove anonymous users
Disallow remote root login
Remove test databases
Reload privilege tables
For most cases, you can safely answer Y to all prompts to secure your MariaDB installation.
Step 5: Verify MariaDB Installation
Log in to the MariaDB shell to confirm the database server is working properly.
bash
CopyEdit
sudo mariadb
You should see the MariaDB prompt:
text
CopyEdit
Welcome to the MariaDB monitor. Commands end with ; or \g. MariaDB [(none)]>
Type exit to leave the MariaDB shell.
Step 6: Allow Remote Connections (Optional)
By default, MariaDB only listens on localhost. If you want to allow remote access:
Open the MariaDB configuration file: bash CopyEdit sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf
Find the line: bash CopyEdit bind-address = 127.0.0.1
Change it to: bash CopyEdit bind-address = 0.0.0.0
Restart MariaDB: bash CopyEdit sudo systemctl restart mariadb
Note: Ensure your firewall allows connections to MariaDB’s default port (3306).
Step 7: Basic MariaDB Management Commands
Here are some useful MariaDB service management commands:
Restart MariaDB: bash CopyEdit sudo systemctl restart mariadb
Stop MariaDB: bash CopyEdit sudo systemctl stop mariadb
Check MariaDB status: bash CopyEdit sudo systemctl status mariadb