If you’re running a server on CentOS and want to store data—for a website, app, or other project—you’ll probably need a database. MariaDB is a solid choice. It’s free, reliable, and works well with most tools that use MySQL.
In this post, I’ll walk you through installing and securing MariaDB on CentOS. I’ll also share tips from experience, and explain each step in plain language. No need to be a tech expert.
What Is MariaDB?
MariaDB is a type of database server. It stores information like usernames, blog posts, or app settings.
It’s similar to MySQL and works with the same commands and structure. Many apps that say they “need MySQL” also work just fine with MariaDB.
I use it on my own CentOS servers. It does the job, and it’s not hard to set up.
Why Use MariaDB?
Here’s why I prefer MariaDB:
- It’s open source and free to use.
- It runs fast on CentOS.
- It works with common apps like WordPress, Drupal, and many others.
- It’s widely supported and regularly updated.
If you’re hosting your own project, MariaDB is a dependable tool that helps you keep control of your data.
Step 1: Update Your System
Before installing new software, it’s a good idea to update your server.
Open your terminal and run:
sudo yum update -y
This checks for any software updates. It helps make sure you’re working with the latest versions.
Step 2: Install MariaDB
Now let’s install MariaDB using the yum
package manager.
Type this:
sudo yum install mariadb-server -y
This downloads and installs MariaDB.
Once it’s done, start the MariaDB service:
sudo systemctl start mariadb
To make sure MariaDB starts every time your server reboots, use:
sudo systemctl enable mariadb
MariaDB is now installed and running.
Step 3: Secure the Installation
Out of the box, MariaDB isn’t secure. But there’s a built-in tool to fix that.
Run this:
sudo mysql_secure_installation
You’ll be asked several questions. Here’s how I answer them:
- Enter current password for root (enter for none):
Just press Enter. - Set root password? [Y/n]
TypeY
, then choose a strong password. - Remove anonymous users? [Y/n]
TypeY
. It’s safer this way. - Disallow root login remotely? [Y/n]
TypeY
. It blocks access from outside the server. - Remove test database and access to it? [Y/n]
TypeY
. Not needed for production. - Reload privilege tables now? [Y/n]
TypeY
.
That’s it. The tool helps close common security holes.
Step 4: Log In and Test
Now let’s check that everything works.
Log into MariaDB with:
sudo mysql -u root -p
You’ll be asked for the password you just set. If successful, you’ll see something like:
Welcome to the MariaDB monitor...
To exit the MariaDB prompt, just type:
exit;
Step 5: Create a New User and Database
Instead of using the root
user for apps, it’s safer to make a separate user and database.
Here’s how:
- Log in to MariaDB:
sudo mysql -u root -p
- Create a new database:
CREATE DATABASE myapp_db;
- Create a new user:
CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'mypassword';
- Give the user access to the new database:
GRANT ALL PRIVILEGES ON myapp_db.* TO 'myuser'@'localhost';
- Reload the permissions:
FLUSH PRIVILEGES;
- Exit:
exit;
Now, myuser
can use myapp_db
, and your root account stays safe.
Commands Recap
Here’s a quick list you can keep handy:
yum install mariadb-server -y
— install MariaDBsystemctl start mariadb
— start the servicesystemctl enable mariadb
— run on bootmysql_secure_installation
— run the security setupmysql -u root -p
— log into MariaDBCREATE DATABASE
— make a new databaseCREATE USER
— make a new userGRANT
— give user accessFLUSH PRIVILEGES
— refresh the permission rules
Why Security Matters
Even if your site is small, security is still important.
Here’s what can happen without it:
- Hackers may find and use your test database.
- Weak passwords can be guessed in seconds.
- Root access could let someone destroy your entire setup.
That’s why I always run mysql_secure_installation
and avoid using root
in apps.
Lessons I Learned
A few small things I’ve picked up along the way:
- Always create a new user for each app.
- Never expose MariaDB to the public internet unless you must.
- Back up your databases regularly.
- Use long passwords that aren’t easy to guess.
Once, I forgot to disable remote root login. A bot tried to brute-force the password for hours before I noticed. That was a wake-up call.
Two Lists to Keep in Mind
What You Should Do:
- Update your CentOS system before installing MariaDB
- Use
mysql_secure_installation
right away - Create separate users for each database
- Set strong passwords
- Make regular backups
What You Should Avoid:
- Using the root account in your apps
- Leaving test databases on the server
- Allowing remote root logins
- Ignoring software updates
- Reusing weak or simple passwords
Final Thoughts
Installing MariaDB on CentOS isn’t hard. But securing it takes a few extra minutes—and it’s worth every second.
Now you have a solid, working setup:
- MariaDB is installed and running.
- The root account is protected.
- A separate user and database are ready for your app.
Have you set up MariaDB before? Or is this your first time? What do you plan to use it for?