MySQL databases are the backbone of most dynamic websites and applications. This guide explains how to create a database, assign users with proper privileges, and configure secure remote access for external applications or developers.


Why This Matters

  • Security: Improper privilege assignment can lead to data leaks or unauthorized changes.
  • Performance: Optimized database settings reduce query execution time.
  • Remote Access: Allows developers or apps to connect securely without exposing sensitive credentials.

Step 1: Create a MySQL Database

  1. Log in to cPanel.
  2. Navigate to Databases → MySQL Database Wizard.
  3. Enter a Database Name (e.g., app_db).
  4. Click Next Step.

Step 2: Create a Database User

  1. Enter a Username (e.g., app_user).
  2. Set a Strong Password:
    • Minimum 12 characters
    • Mix of uppercase, lowercase, numbers, and symbols
  3. Click Create User.

Step 3: Assign Privileges

  • For most apps, select ALL PRIVILEGES.
  • For security-sensitive environments:
    • Grant only SELECT, INSERT, UPDATE, DELETE.
  • Click Next Step to complete setup.

Step 4: Enable Remote Access

  1. Go to Remote MySQL in cPanel.
  2. Add the IP address of the remote server or developer machine.
    • Example: 203.0.113.45
  3. Click Add Host.
  4. Tip: Use a static IP or VPN for consistent access.

Step 5: Secure Remote Connections

  • Use SSL/TLS for encrypted connections.
  • Configure MySQL to require SSL:
     
     
    GRANT ALL PRIVILEGES ON app_db.* TO 'app_user'@'%' REQUIRE SSL;
     
     
  • Verify SSL with:
     
     
     
    SHOW VARIABLES LIKE '%ssl%';
     

Advanced Configuration

  • Change Default Port: Modify my.cnf to use a non-standard port (e.g., 3307).
  • Limit Connections: Set max_connections in MySQL config to prevent overload.
  • Enable Query Cache: Improves performance for repeated queries.

Troubleshooting

  • Error: Access Denied
    • Check username, password, and host permissions.
  • Remote Connection Timeout
    • Ensure port 3306 (or custom port) is open in firewall.
  • SSL Errors
    • Verify certificate paths and permissions.

Security Best Practices

  • Never use root for remote access.
  • Rotate passwords regularly.
  • Monitor logs for suspicious queries:
     
     
     
    tail -f /var/lib/mysql/mysql.log
     

Related Articles

  • How to Optimize MySQL Performance in cPanel
  • Setting Up phpMyAdmin for Remote Database Management
Hai trovato utile questa risposta? 31 Utenti hanno trovato utile questa risposta (122 Voti)