Installing MySQL or MariaDB

Installing MySQL or MariaDB

MySQL and MariaDB are the most widely used relational databases for web applications. MariaDB is a drop-in replacement for MySQL with better performance on many workloads.

Install MariaDB (Recommended)

Ubuntu/Debian:

apt update
apt install mariadb-server -y
systemctl enable mariadb
systemctl start mariadb

CentOS/AlmaLinux/Rocky:

dnf install mariadb-server -y
systemctl enable mariadb
systemctl start mariadb

Secure the Installation

mysql_secure_installation

Follow the prompts to: set a root password, remove anonymous users, disable remote root login, and remove the test database.

Create a Database and User

mysql -u root -p

CREATE DATABASE myapp;
CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'StrongPassword123!';
GRANT ALL PRIVILEGES ON myapp.* TO 'myuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Basic MySQL Commands

SHOW DATABASES;
USE myapp;
SHOW TABLES;
SELECT * FROM users LIMIT 10;
DROP DATABASE testdb;

Install MySQL 8 Instead (if required)

apt install mysql-server -y

The commands above work identically for MySQL 8.

Backup a Database

mysqldump -u root -p myapp > myapp_backup.sql

Restore a Database

mysql -u root -p myapp < myapp_backup.sql
  • 0 Пользователи нашли это полезным
Помог ли вам данный ответ?

Связанные статьи

Managing Users and Groups

Managing Users and Groups on Linux Proper user management is essential for server security. Avoid...

Managing Services with systemctl

Managing Services with systemctl systemctl is the standard tool for managing services on modern...

Monitoring Server Resources

Monitoring Server Resources Keeping an eye on your server's resource usage helps you identify...

Scheduling Tasks with Cron

Scheduling Tasks with Cron Cron allows you to schedule commands to run automatically at set...

Installing and Configuring Nginx

Installing and Configuring Nginx Nginx is a high-performance web server and reverse proxy widely...