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:
sudo apt update5. Install MariaDB 11.4.3
Now you can install MariaDB 11.4.3 using the following command:
sudo apt install mariadb-server mariadb-client -y6. Start and Enable MariaDB Service
After installation, start the MariaDB service and enable it to automatically start on system boot:
sudo systemctl start mariadb
sudo systemctl enable mariadb7. Secure the MariaDB Installation
MariaDB includes a security script to remove default settings that are insecure. Run this script:
sudo mysql_secure_installationYou 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:
sudo systemctl status mariadbYou should see the service status as "active" (running).
Additionally, log into the MariaDB shell:
sudo mariadb -u root -pEnter the root password you created earlier, and you'll be logged into the MariaDB shell. To confirm the version, run:
SELECT VERSION();You should see something like:
+----------------+
| VERSION() |
+----------------+
| 11.4.3-MariaDB |
+----------------+9. Basic Configuration (Optional)
You can configure MariaDB by editing the my.cnf configuration file:
sudo nano /etc/mysql/my.cnfMake any changes you need, then restart the service:
sudo systemctl restart mariadbCommon Commands
Start MariaDB:
sudo systemctl start mariadbStop MariaDB:
sudo systemctl stop mariadbRestart MariaDB:
sudo systemctl restart mariadbCheck MariaDB Status:
sudo systemctl status mariadb
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:
sudo yum update -y2. 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:
sudo nano /etc/yum.repos.d/MariaDB.repoAdd the following content based on your CentOS version:
For CentOS 7:
[mariadb]
name = MariaDB
baseurl = https://mirror.mariadb.org/repo/11.4/centos7-amd64
gpgkey=https://mariadb.org/mariadb_release_signing_key.asc
gpgcheck=1For CentOS 8 / Stream:
[mariadb]
name = MariaDB
baseurl = https://mirror.mariadb.org/repo/11.4/centos8-amd64
gpgkey=https://mariadb.org/mariadb_release_signing_key.asc
gpgcheck=1Save 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.
sudo yum install MariaDB-server MariaDB-client -y4. Start and Enable MariaDB Service
Once the installation is complete, start MariaDB and enable it to start on boot:
sudo systemctl start mariadb
sudo systemctl enable mariadbYou can check if the service is running correctly:
sudo systemctl status mariadbThe 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:
sudo mysql_secure_installationYou'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:
sudo mysql -u root -pEnter the root password, and you'll be logged in. To check the installed version, run:
SELECT VERSION();This should output something like:
+----------------+
| VERSION() |
+----------------+
| 11.4.3-MariaDB |
+----------------+7. Firewall Configuration (Optional)
If your server uses firewalld, you'll need to allow MariaDB service through the firewall to allow external connections.
sudo firewall-cmd --permanent --add-service=mysql
sudo firewall-cmd --reload8. 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:
sudo nano /etc/my.cnfMake any necessary changes and save. After making changes, restart MariaDB:
sudo systemctl restart mariadbCommon Commands
Start MariaDB:
sudo systemctl start mariadbStop MariaDB:
sudo systemctl stop mariadbRestart MariaDB:
sudo systemctl restart mariadbEnable MariaDB at Boot:
sudo systemctl enable mariadbCheck MariaDB Status:
sudo systemctl status mariadb
Last updated
Was this helpful?