Relational Database

    Install MySQL on RamNode

    Deploy MySQL on your RamNode VPS hosting. Set up the world's most popular open-source relational database with reliable performance and proven stability for your applications.

    Ubuntu/CentOS
    MySQL 8.0+
    ⏱️ 20-30 minutes

    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
    2

    Initial Server Setup

    Connect to your RamNode VPS and prepare the environment:

    Connect via SSH
    ssh root@your-server-ip
    Update System Packages
    # 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.

    3

    Install MySQL Server

    Install MySQL server based on your distribution:

    Ubuntu/Debian Installation

    Install MySQL on Ubuntu
    sudo apt update
    sudo apt install mysql-server -y

    CentOS/RHEL Installation

    Install MySQL on CentOS
    # 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 -y
    Start and Enable MySQL Service
    sudo systemctl start mysqld
    sudo systemctl enable mysqld
    Check MySQL Status
    sudo systemctl status mysqld
    mysql --version

    Why 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.

    4

    Secure MySQL Installation

    Run the security script to secure your MySQL installation:

    Find Temporary Root Password (CentOS only)
    # For CentOS installations, find the temporary root password
    sudo grep 'temporary password' /var/log/mysqld.log
    Run Security Installation
    sudo mysql_secure_installation

    Follow 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)
    Test Root Login
    mysql -u root -p
    Check MySQL Version and Status
    -- 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.

    5

    Create Database and User

    Create a new database and user for your applications:

    Login to MySQL
    mysql -u root -p
    Create Database and User
    -- 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;
    Test New User Connection
    mysql -u myapp_user -p myapp_db
    Test Database Operations
    -- 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.

    6

    Configure Remote Access

    Enable remote connections to your MySQL server:

    Edit MySQL Configuration
    # Ubuntu/Debian
    sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
    
    # CentOS/RHEL
    sudo nano /etc/my.cnf

    Find and modify the bind-address setting:

    Enable Remote Connections
    [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.1
    Create Remote User
    mysql -u root -p
    Grant Remote Access
    -- 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;
    Restart MySQL
    sudo systemctl restart mysqld
    Configure Firewall
    # Ubuntu (UFW)
    sudo ufw allow 3306/tcp
    sudo ufw reload
    
    # CentOS (firewalld)
    sudo firewall-cmd --permanent --add-port=3306/tcp
    sudo firewall-cmd --reload
    Test Remote Connection
    mysql -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.

    7

    Performance Optimization

    Optimize MySQL for your RamNode VPS:

    Create Custom Configuration
    # Ubuntu/Debian
    sudo nano /etc/mysql/mysql.conf.d/99-custom.cnf
    
    # CentOS/RHEL
    sudo nano /etc/my.cnf.d/custom.cnf

    Memory Configuration

    Optimal Memory Settings
    [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_ci
    Apply Configuration Changes
    sudo systemctl restart mysqld
    sudo systemctl status mysqld
    Monitor Performance
    # 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.

    8

    Backup Strategy

    Set up automated backups for your MySQL databases:

    Create Backup Directory
    sudo mkdir -p /var/backups/mysql
    sudo chown mysql:mysql /var/backups/mysql
    Create Backup Script
    sudo nano /usr/local/bin/mysql_backup.sh
    MySQL Backup Script
    #!/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"
    Make Script Executable and Secure
    sudo chmod +x /usr/local/bin/mysql_backup.sh
    sudo chmod 700 /usr/local/bin/mysql_backup.sh
    Test Backup Script
    sudo /usr/local/bin/mysql_backup.sh
    Schedule Daily Backups
    sudo 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>&1

    Backup Restoration

    Restore Database from Backup
    # 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.

    9

    Monitoring and Maintenance

    Monitor your MySQL installation:

    Useful Monitoring Queries
    -- 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';
    Create Monitoring Script
    nano /usr/local/bin/mysql_monitor.sh
    MySQL Monitoring Script
    #!/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)'
    Make Monitoring Script Executable
    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

    10

    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.

    Production Ready
    Secure Setup
    Performance Optimized