DocsServer ManagementDatabase Setup & Configuration
Server Management 7 min read

Database Setup & Configuration

Install and configure MySQL, PostgreSQL, or Redis on your server.

Database Setup & Configuration

MySQL / MariaDB

Installation

bash
apt update
apt install mysql-server -y
mysql_secure_installation

Create a Database and User

sql
CREATE DATABASE myapp;
CREATE USER 'appuser'@'localhost' IDENTIFIED BY 'secure_password';
GRANT ALL PRIVILEGES ON myapp.* TO 'appuser'@'localhost';
FLUSH PRIVILEGES;

Performance Tuning

Edit /etc/mysql/mysql.conf.d/mysqld.cnf:

ini
[mysqld]
innodb_buffer_pool_size = 4G    # 50-70% of available RAM
innodb_log_file_size = 512M
max_connections = 200
query_cache_size = 64M

PostgreSQL

Installation

bash
apt update
apt install postgresql postgresql-contrib -y
systemctl enable postgresql

Create a Database

bash
sudo -u postgres psql
CREATE DATABASE myapp;
CREATE USER appuser WITH ENCRYPTED PASSWORD 'secure_password';
GRANT ALL PRIVILEGES ON DATABASE myapp TO appuser;

Redis

Installation

bash
apt update
apt install redis-server -y

Configuration

Edit /etc/redis/redis.conf:

ini
maxmemory 2gb
maxmemory-policy allkeys-lru
requirepass your_redis_password

Test Connection

bash
redis-cli
AUTH your_redis_password
PING
# Response: PONG
Need help? Chat with us!