Install MariaDB on Linux
Learn how to install mariadb service on different linux distributions
Prerequisites
A running Debian-based system (e.g., Ubuntu 22.04, Debian 11).
Root or sudo access.
A stable internet connection for package downloads.
Step-by-Step Installation Guide
1. Update Your System
First, make sure your package lists are up to date.
sudo apt update
sudo apt upgrade -y2. Install Prerequisites
MariaDB requires some dependencies to be installed on your system, like software-properties-common to manage repositories.
sudo apt install software-properties-common dirmngr -y3. Add the MariaDB 11.4 Repository
To install the latest version of MariaDB (11.4.3), you need to add the official MariaDB repository to your system.
Import the MariaDB GPG key:
sudo apt-key adv --fetch-keys 'https://mariadb.org/mariadb_release_signing_key.asc'Add the MariaDB repository:
sudo add-apt-repository 'deb [arch=amd64] https://mirror.mariadb.org/repo/11.4/debian bullseye main'If you're using a different Debian-based distribution, replace
bullseyewith your version codename (e.g.,focalfor Ubuntu 20.04).
4. Update Package Lists Again
After adding the MariaDB repository, update your package list to include the new packages from MariaDB:
5. Install MariaDB 11.4.3
Now you can install MariaDB 11.4.3 using the following command:
6. Start and Enable MariaDB Service
After installation, start the MariaDB service and enable it to automatically start on system boot:
7. Secure the MariaDB Installation
MariaDB includes a security script to remove default settings that are insecure. Run this script:
You will be prompted to:
Set a root password (if not set during installation).
Remove anonymous users.
Disallow remote root login.
Remove the test database.
Reload privilege tables.
Answer "Y" to all prompts for a secure installation.
8. Verify Installation
To verify that MariaDB is correctly installed and running, use:
You should see the service status as "active" (running).
Additionally, log into the MariaDB shell:
Enter the root password you created earlier, and you'll be logged into the MariaDB shell. To confirm the version, run:
You should see something like:
9. Basic Configuration (Optional)
You can configure MariaDB by editing the my.cnf configuration file:
Make any changes you need, then restart the service:
Common Commands
Start MariaDB:
Stop MariaDB:
Restart MariaDB:
Check MariaDB Status:
Prerequisites
A running CentOS system (CentOS 7, CentOS 8, or CentOS Stream).
Root or sudo access.
Internet connection for package downloads.
Step-by-Step Installation Guide
1. Update Your System
Before beginning, update your system packages to ensure everything is up-to-date:
2. Add the MariaDB 11.4 Repository
MariaDB 11.4 is not available by default in the CentOS repositories, so we need to add the MariaDB official repository.
Create a repository file:
Add the following content based on your CentOS version:
For CentOS 7:
For CentOS 8 / Stream:
Save and exit the file by pressing
CTRL + X, thenY, andEnter.
3. Install MariaDB 11.4.3
Now that the MariaDB repository is added, you can install MariaDB 11.4.3.
4. Start and Enable MariaDB Service
Once the installation is complete, start MariaDB and enable it to start on boot:
You can check if the service is running correctly:
The status should be "active (running)".
5. Secure MariaDB Installation
MariaDB includes a script to secure the installation by removing insecure default settings. Run the script to improve security:
You'll be prompted to:
Set a root password (if not already set).
Remove anonymous users.
Disallow root remote login.
Remove the test database.
Reload privilege tables.
Answer "Y" to all prompts for better security.
6. Verify Installation
To verify the installation of MariaDB 11.4.3, log into the MariaDB shell:
Enter the root password, and you'll be logged in. To check the installed version, run:
This should output something like:
7. Firewall Configuration (Optional)
If your server uses firewalld, you'll need to allow MariaDB service through the firewall to allow external connections.
8. Basic Configuration (Optional)
You can configure MariaDB by editing its main configuration file, typically located at /etc/my.cnf or /etc/my.cnf.d/. For example:
Make any necessary changes and save. After making changes, restart MariaDB:
Common Commands
Start MariaDB:
Stop MariaDB:
Restart MariaDB:
Enable MariaDB at Boot:
Check MariaDB Status:
Last updated
Was this helpful?