🎯 Objective
Learn how to install, start, and configure a database server so applications can store and retrieve data securely and efficiently.
A database server stores structured data and allows applications to communicate with it using SQL.
Common database servers include:
For this exercise we will configure MariaDB, a popular open-source database server.
# 1️⃣ Install MariaDB Server
Ubuntu / Debian
sudo apt update
sudo apt install mariadb-server -yRHEL / CentOS / Amazon Linux
sudo yum install mariadb-server -y# 2️⃣ Start and Enable Database Service
Start the server:
sudo systemctlstart mariadbEnable it at boot:
sudo systemctl enable mariadbCheck status:
sudo systemctl status mariadb# 3️⃣ Secure the Database Installation
Run the security script:
sudo mysql_secure_installationThis script helps you:
Example prompt:
Set root password? Y
Remove anonymous users? Y
Disallow root login remotely? Y
Remove test database? Y
Reload privilege tables? Y# 4️⃣ Login to Database Server
sudo mysqlYou will see:
MariaDB [(none)]>Exit:
exit;# 5️⃣ Create a Database
CREATE DATABASE companydb;Show databases:
SHOW DATABASES;# 6️⃣ Create a Database User
CREATE USER 'dbuser'@'localhost' IDENTIFIED BY 'StrongPassword';Grant privileges:
GRANT ALL PRIVILEGES ON companydb.*TO'dbuser'@'localhost';Apply privileges:
FLUSH PRIVILEGES;# 7️⃣ Test Database Connection
Login using the new user:
mysql -u dbuser -p companydb# 8️⃣ Check Database Port
Default database port:
3306Check listening port:
sudo ss-tunlp | grep3306# 🧠 Database Server Architecture
Client Application
│
▼
Database Server
│
▼
Databases
│
┌──────┼──────┐
▼ ▼ ▼
Tables Tables Tables# 🧪 Troubleshooting
Check service status
sudo systemctl status mariadbRestart database server
sudo systemctl restart mariadbView logs
sudo journalctl -u mariadb# ✅ Summary