Prerequisites
Before starting, ensure you have:
Server Requirements
- • RamNode VPS (1GB+ RAM minimum)
- • Ubuntu 20.04+ or Debian 11+
- • 1+ CPU cores
- • 10GB+ disk space available
- • SSH access to your VPS
Access Requirements
- • Root or sudo access
- • Basic Linux command knowledge
- • Understanding of database concepts
- • SSH client installed
Initial Server Setup
Connect to your RamNode VPS and prepare the environment:
ssh root@your-server-ipsudo apt update
sudo apt upgrade -ysudo apt install -y software-properties-common dirmngr apt-transport-https💡 System Tip: Always ensure your system is up-to-date before installing database software to avoid compatibility issues and security vulnerabilities.
Install MariaDB Server
Install MariaDB server and client packages:
sudo apt-key adv --fetch-keys 'https://mariadb.org/mariadb_release_signing_key.asc'
sudo add-apt-repository 'deb [arch=amd64,arm64,ppc64el] https://mirrors.xtom.nl/mariadb/repo/10.11/ubuntu jammy main'sudo apt updatesudo apt install -y mariadb-server mariadb-clientsudo systemctl start mariadb
sudo systemctl enable mariadbsudo systemctl status mariadb
mysql --versionWhy MariaDB?
MariaDB is a high-performance, open-source relational database that serves as a drop-in replacement for MySQL. It offers enhanced performance, better security features, more storage engines, and active development by the original MySQL creators.
Secure MariaDB Installation
Run the security script to secure your MariaDB installation:
sudo mysql_secure_installationFollow the prompts and make these security choices:
Security Configuration Prompts
- • Enter current password for root: Press Enter (no password set yet)
- • Set root password: Y (Yes) - Choose a strong password
- • Remove anonymous users: Y (Yes)
- • Disallow root login remotely: Y (Yes, for security)
- • Remove test database: Y (Yes)
- • Reload privilege tables: Y (Yes)
sudo mysql -u root -p-- Check MariaDB version and status
SELECT VERSION();
SHOW STATUS LIKE 'Uptime';
-- Exit MySQL prompt
EXIT;🔐 Security: Store your root password securely! Consider using a password manager for database credentials.
Create Database and User
Create a new database and user for your applications:
sudo mysql -u root -p-- Create a new database
CREATE DATABASE myapp_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- Create a new user with password
CREATE USER 'myapp_user'@'localhost' IDENTIFIED BY 'secure_user_password';
-- Grant privileges to the user
GRANT ALL PRIVILEGES ON myapp_db.* TO 'myapp_user'@'localhost';
-- Flush privileges to ensure they take effect
FLUSH PRIVILEGES;
-- Show databases
SHOW DATABASES;
-- Show users
SELECT User, Host FROM mysql.user;
-- Exit
EXIT;mysql -u myapp_user -p myapp_db-- Create a test table
CREATE TABLE test_table (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- Insert test data
INSERT INTO test_table (name) VALUES ('Test Entry');
-- Query the data
SELECT * FROM test_table;
-- Drop test table
DROP TABLE test_table;
-- Exit
EXIT;✅ Database and user created successfully! Your applications can now connect to MariaDB.
Configure Remote Access
Enable remote connections to your MariaDB server:
sudo nano /etc/mysql/mariadb.conf.d/50-server.cnfFind and modify the bind-address setting:
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address = 0.0.0.0sudo mysql -u root -p-- Create user for remote access (replace with your IP)
CREATE USER 'myapp_user'@'%' IDENTIFIED BY 'secure_password';
-- Or create user for specific IP range
CREATE USER 'myapp_user'@'192.168.1.%' IDENTIFIED BY 'secure_password';
-- Grant privileges
GRANT ALL PRIVILEGES ON myapp_db.* TO 'myapp_user'@'%';
-- Flush privileges
FLUSH PRIVILEGES;
-- Exit
EXIT;sudo systemctl restart mariadbsudo ufw allow 3306/tcp
sudo ufw reloadmysql -h your-server-ip -u myapp_user -p myapp_db🔒 Security Warning: Only allow remote access from trusted networks. Consider using SSH tunneling or VPN for additional security.
Performance Optimization
Optimize MariaDB for your RamNode VPS:
sudo nano /etc/mysql/mariadb.conf.d/99-custom.cnfMemory Configuration
[mysqld]
# Basic Settings
max_connections = 100
thread_cache_size = 8
table_open_cache = 2000
# MyISAM Settings
key_buffer_size = 32M
# InnoDB Settings (adjust based on your RAM)
# For 2GB RAM VPS
innodb_buffer_pool_size = 512M
innodb_log_file_size = 128M
# For 4GB RAM VPS
# innodb_buffer_pool_size = 1G
# innodb_log_file_size = 256M
# For 8GB RAM VPS
# innodb_buffer_pool_size = 2G
# innodb_log_file_size = 512M
# Additional InnoDB Settings
innodb_flush_method = O_DIRECT
innodb_log_buffer_size = 16M
innodb_flush_log_at_trx_commit = 2
innodb_file_per_table = 1
# Query Cache (if using older versions)
query_cache_type = 1
query_cache_size = 32M
# Slow Query Log
slow_query_log = 1
slow_query_log_file = /var/log/mysql/slow.log
long_query_time = 2
# Binary Logging
log_bin = /var/log/mysql/mysql-bin.log
expire_logs_days = 7
max_binlog_size = 100Msudo systemctl restart mariadb
sudo systemctl status mariadb# Check status variables
sudo mysql -u root -p -e "SHOW STATUS LIKE 'Innodb_buffer_pool%';"
# Check process list
sudo mysql -u root -p -e "SHOW PROCESSLIST;"
# Check engine status
sudo mysql -u root -p -e "SHOW ENGINE INNODB STATUS\G"⚡ Performance Tip: Monitor your database performance with tools like mysqltuner to get personalized optimization recommendations.
Backup Strategy
Set up automated backups for your MariaDB databases:
sudo mkdir -p /var/backups/mariadb
sudo chown mysql:mysql /var/backups/mariadbsudo nano /usr/local/bin/mariadb_backup.sh#!/bin/bash
# MariaDB backup script
BACKUP_DIR="/var/backups/mariadb"
DATE=$(date +%Y%m%d_%H%M%S)
MYSQL_USER="root"
MYSQL_PASSWORD="your_root_password"
DATABASES="myapp_db" # Add your database names here
# Create backup directory if it doesn't exist
mkdir -p $BACKUP_DIR
# Backup each database
for DATABASE in $DATABASES; do
echo "Backing up database: $DATABASE"
mysqldump -u $MYSQL_USER -p$MYSQL_PASSWORD --single-transaction --routines --triggers $DATABASE | gzip > $BACKUP_DIR/${DATABASE}_backup_$DATE.sql.gz
done
# Backup all databases (alternative)
mysqldump -u $MYSQL_USER -p$MYSQL_PASSWORD --all-databases --single-transaction --routines --triggers | gzip > $BACKUP_DIR/all_databases_backup_$DATE.sql.gz
# Clean up old backups (keep 7 days)
find $BACKUP_DIR -name "*.sql.gz" -mtime +7 -delete
echo "Backup completed: $DATE"sudo chmod +x /usr/local/bin/mariadb_backup.sh
sudo chmod 700 /usr/local/bin/mariadb_backup.shsudo /usr/local/bin/mariadb_backup.shsudo crontab -e
# Add this line for daily backups at 2 AM
0 2 * * * /usr/local/bin/mariadb_backup.sh >> /var/log/mariadb_backup.log 2>&1Backup Restoration
# Restore a specific database
gunzip -c /var/backups/mariadb/myapp_db_backup_YYYYMMDD_HHMMSS.sql.gz | mysql -u root -p myapp_db
# Restore all databases
gunzip -c /var/backups/mariadb/all_databases_backup_YYYYMMDD_HHMMSS.sql.gz | mysql -u root -p💾 Backup Tip: Test your backup restoration process regularly to ensure your backups are working correctly and your data is protected.
Monitoring and Maintenance
Monitor your MariaDB installation:
-- Check database connections
SHOW STATUS LIKE 'Threads_connected';
-- Monitor slow queries
SHOW STATUS LIKE 'Slow_queries';
-- Check database sizes
SELECT
table_schema AS 'Database',
ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) AS 'Size (MB)'
FROM information_schema.tables
GROUP BY table_schema;
-- Monitor InnoDB buffer pool usage
SHOW STATUS LIKE 'Innodb_buffer_pool_%';
-- Check for locked tables
SHOW OPEN TABLES WHERE In_use > 0;
-- View current processes
SHOW PROCESSLIST;
-- Check uptime
SHOW STATUS LIKE 'Uptime';nano /usr/local/bin/mariadb_monitor.sh#!/bin/bash
echo "=== MariaDB Status ==="
sudo systemctl status mariadb --no-pager -l
echo -e "\n=== Connection Count ==="
mysql -u root -p -e "SHOW STATUS LIKE 'Threads_connected';" 2>/dev/null
echo -e "\n=== Database Sizes ==="
mysql -u root -p -e "SELECT table_schema AS 'Database', ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) AS 'Size (MB)' FROM information_schema.tables GROUP BY table_schema;" 2>/dev/null
echo -e "\n=== InnoDB Buffer Pool ==="
mysql -u root -p -e "SHOW STATUS LIKE 'Innodb_buffer_pool_pages_%';" 2>/dev/null
echo -e "\n=== Slow Queries ==="
mysql -u root -p -e "SHOW STATUS LIKE 'Slow_queries';" 2>/dev/null
echo -e "\n=== Disk Usage ==="
df -h | grep -E '(Filesystem|/$|/var)'chmod +x /usr/local/bin/mariadb_monitor.sh
./usr/local/bin/mariadb_monitor.sh📊 Monitoring Tip: Consider installing MySQLTuner for automated performance analysis: sudo apt install mysqltuner then run mysqltuner.
Troubleshooting
Common issues and solutions:
🛠️ Support: For additional help, check MariaDB documentation, community forums, or contact RamNode support for VPS-specific issues.
🎉 MariaDB Successfully Deployed!
Your MariaDB database server is now running on RamNode VPS with enhanced performance, security, and MySQL compatibility. You're ready to deploy production applications with confidence.
