This guide covers how to set up and configure mysql on a Linux VPS. Whether you're running a production environment or a development setup, these instructions will help you get started quickly and securely.
Prerequisites
- Basic familiarity with the Linux command line
- A remote storage destination (S3, B2, or another server)
- Root or sudo access to the server
- A VPS running Ubuntu 22.04 or later (2GB+ RAM recommended)
- Sufficient storage for backups (2-3x data size)
Backup Configuration
For production deployments, consider implementing high availability by running multiple instances behind a load balancer. This approach provides both redundancy and improved performance under heavy load.
# Install and initialize backup tool
sudo apt install -y mysql
mysql init --repo /backup/repo
# Create first backup
mysql backup --repo /backup/repo /etc /home /var/www
# List backups
mysql snapshots --repo /backup/repo
This configuration provides a good balance between performance and resource usage. For high-traffic scenarios, you may need to increase the limits further.
Scheduling Automated Backups
Performance benchmarks show that properly tuned mysql can handle significantly more concurrent connections than the default configuration. The key improvements come from adjusting worker processes and connection pooling.
# Automated backup script: /usr/local/bin/backup.sh
#!/bin/bash
set -euo pipefail
BACKUP_REPO="/backup/repo"
LOG_FILE="/var/log/backup.log"
DATE=$(date +%Y-%m-%d_%H-%M)
echo "[$DATE] Starting backup..." >> $LOG_FILE
# Database dump
mysqldump --all-databases | gzip > /tmp/db-$DATE.sql.gz
# Run backup
mysql backup --repo $BACKUP_REPO /etc /home /var/www /tmp/db-$DATE.sql.gz
# Cleanup old backups (keep 30 days)
mysql forget --repo $BACKUP_REPO --keep-daily 7 --keep-weekly 4 --keep-monthly 3 --prune
rm /tmp/db-$DATE.sql.gz
echo "[$DATE] Backup completed successfully" >> $LOG_FILE
The configuration above sets the recommended values for a VPS with 2-4GB of RAM. Adjust the memory-related settings proportionally if your server has different specifications.
Next Steps
With mysql now set up and running, consider implementing monitoring to track performance metrics over time. Regularly review your configuration as your workload changes and scale resources accordingly.