Server ManagementIntermediate15 min
How to Install and Secure MySQL/MariaDB Database
Step-by-step guide to installing MySQL or MariaDB database server with security best practices
Introduction
MySQL and MariaDB are popular relational database management systems. This guide covers installation and security configuration.
Step 1: Install MariaDB
Install MariaDB server from the default repository.
sudo apt update
sudo apt install mariadb-serverStep 2: Start MariaDB Service
Enable and start the MariaDB service.
sudo systemctl start mariadb
sudo systemctl enable mariadbStep 3: Run Security Script
Run the security script to improve database security.
sudo mysql_secure_installationStep 4: Create Database and User
Create a new database and user for your application.
sudo mysql
CREATE DATABASE myapp;
CREATE USER 'myappuser'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON myapp.* TO 'myappuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;Step 5: Configure Remote Access
If needed, configure MariaDB to allow remote connections.
sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf
# Comment out: bind-address = 127.0.0.1
sudo systemctl restart mariadbConclusion
MariaDB is now installed and secured. Remember to use strong passwords and limit database user privileges.
#MySQL#MariaDB#Database#SQL#Security