Prerequisites
Before starting, ensure you have:
Server Requirements
- • RamNode VPS (1GB+ RAM minimum)
- • Ubuntu 20.04+ or CentOS 7+
- • 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-ip# For Ubuntu/Debian
sudo apt update && apt upgrade -y
# For CentOS/RHEL
sudo yum update -y💡 System Tip: Always ensure your system is up-to-date before installing database software to avoid compatibility issues and security vulnerabilities.
Install MySQL Server
Install MySQL server based on your distribution:
Ubuntu/Debian Installation
sudo apt update
sudo apt install mysql-server -yCentOS/RHEL Installation
# Add MySQL repository
sudo yum install https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm -y
# Install MySQL server
sudo yum install mysql-community-server -ysudo systemctl start mysqld
sudo systemctl enable mysqldsudo systemctl status mysqld
mysql --versionWhy MySQL?
MySQL is the world's most popular open-source relational database management system. It's known for its reliability, performance, and ease of use, making it the foundation for many web applications, e-commerce platforms, and data warehousing solutions.
Secure MySQL Installation
Run the security script to secure your MySQL installation:
# For CentOS installations, find the temporary root password
sudo grep 'temporary password' /var/log/mysqld.logsudo mysql_secure_installationFollow the prompts and make these security choices:
Security Configuration Prompts
- • Enter current password for root: Enter temporary password (CentOS) or press Enter (Ubuntu)
- • 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)
mysql -u root -p-- Check MySQL version
SELECT VERSION();
-- Check server status
SHOW STATUS LIKE 'Uptime';
-- Exit MySQL prompt
EXIT;🔐 Security: Store your root password securely! Use a strong, unique password and consider using a password manager.
Create Database and User
Create a new database and user for your applications:
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 MySQL.
Configure Remote Access
Enable remote connections to your MySQL server:
# Ubuntu/Debian
sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
# CentOS/RHEL
sudo nano /etc/my.cnfFind and modify the bind-address setting:
[mysqld]
# Change bind-address to allow remote connections
bind-address = 0.0.0.0
# Or comment out the bind-address line entirely
# bind-address = 127.0.0.1mysql -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 mysqld# Ubuntu (UFW)
sudo ufw allow 3306/tcp
sudo ufw reload
# CentOS (firewalld)
sudo firewall-cmd --permanent --add-port=3306/tcp
sudo firewall-cmd --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 MySQL for your RamNode VPS:
# Ubuntu/Debian
sudo nano /etc/mysql/mysql.conf.d/99-custom.cnf
# CentOS/RHEL
sudo nano /etc/my.cnf.d/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 (MySQL 5.7 and earlier)
# 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 = mysql-bin
expire_logs_days = 7
max_binlog_size = 100M
# Character Set
character_set_server = utf8mb4
collation_server = utf8mb4_unicode_cisudo systemctl restart mysqld
sudo systemctl status mysqld# Check status variables
mysql -u root -p -e "SHOW STATUS LIKE 'Innodb_buffer_pool%';"
# Check process list
mysql -u root -p -e "SHOW PROCESSLIST;"
# Check engine status
mysql -u root -p -e "SHOW ENGINE INNODB STATUS\G"⚡ Performance Tip: Use tools like mysqltuner and pt-mysql-summary for automated performance analysis and recommendations.
Backup Strategy
Set up automated backups for your MySQL databases:
sudo mkdir -p /var/backups/mysql
sudo chown mysql:mysql /var/backups/mysqlsudo nano /usr/local/bin/mysql_backup.sh#!/bin/bash
# MySQL backup script
BACKUP_DIR="/var/backups/mysql"
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/mysql_backup.sh
sudo chmod 700 /usr/local/bin/mysql_backup.shsudo /usr/local/bin/mysql_backup.shsudo crontab -e
# Add this line for daily backups at 2 AM
0 2 * * * /usr/local/bin/mysql_backup.sh >> /var/log/mysql_backup.log 2>&1Backup Restoration
# Restore a specific database
gunzip -c /var/backups/mysql/myapp_db_backup_YYYYMMDD_HHMMSS.sql.gz | mysql -u root -p myapp_db
# Restore all databases
gunzip -c /var/backups/mysql/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 MySQL 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/mysql_monitor.sh#!/bin/bash
echo "=== MySQL Status ==="
sudo systemctl status mysqld --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/mysql_monitor.sh
./usr/local/bin/mysql_monitor.sh📊 Monitoring Tip: Install MySQLTuner for automated performance analysis: wget http://mysqltuner.pl/ -O mysqltuner.pl && chmod +x mysqltuner.pl && ./mysqltuner.pl
Troubleshooting
Common issues and solutions:
🛠️ Support: For additional help, check MySQL documentation, community forums, or contact RamNode support for VPS-specific issues.
🎉 MySQL Successfully Deployed!
Your MySQL database server is now running on RamNode VPS with reliable performance and proven stability. You're ready to deploy production applications with the world's most popular open-source database.
