Database Management

    Create and manage MySQL databases for your websites and applications

    Overview

    MySQL databases are essential for dynamic websites, content management systems like WordPress, and web applications. cPanel provides an easy interface to create and manage your databases.

    MySQL Databases

    Create and manage relational databases for your applications

    Database Users

    Control access with separate users and permissions

    phpMyAdmin

    Web-based interface for database administration

    Remote Access

    Connect to databases from external applications

    Creating a MySQL Database

    Step 1: Access MySQL Databases

    1. Log into your cPanel account
    2. Navigate to the "Databases" section
    3. Click on "MySQL Databases"

    Step 2: Create New Database

    1. In the "Create New Database" section, enter your database name
    2. Database names are prefixed with your cPanel username (e.g., username_dbname)
    3. Click "Create Database"

    Use descriptive names like "wordpress" or "store" so you can easily identify the database purpose.

    Creating a Database User

    Step 1: Add New User

    1. Scroll down to "Add New User" section
    2. Enter a username (will be prefixed with your cPanel username)
    3. Enter a strong password or use the Password Generator
    4. Click "Create User"

    Password Best Practice

    Always use the Password Generator to create a strong, random password. Store credentials securely and never share them.

    Assigning User to Database

    Step 1: Add User To Database

    1. Scroll to "Add User To Database" section
    2. Select the user from the dropdown menu
    3. Select the database from the dropdown menu
    4. Click "Add"

    Step 2: Set Privileges

    Choose the privileges for this user on the database:

    • ALL PRIVILEGES - Full access (recommended for most applications)
    • SELECT - Read-only access
    • INSERT, UPDATE, DELETE - Modify data
    • CREATE, DROP, ALTER - Modify structure

    Click "Make Changes" to save the privileges.

    Using phpMyAdmin

    phpMyAdmin is a web-based tool for managing MySQL databases. Access it from cPanel:

    1. In cPanel, go to "Databases" section
    2. Click "phpMyAdmin"
    3. Select your database from the left sidebar
    4. Use the interface to manage tables, run queries, import/export data

    Common phpMyAdmin Tasks:

    • • Browse and edit table data
    • • Run SQL queries
    • • Import SQL files
    • • Export database backups
    • • Create and modify tables
    • • Search across tables

    Database Connection Information

    Use these settings to connect your application to the database:

    Database Host:localhost
    Database Name:username_dbname
    Database User:username_dbuser
    Database Password:your_password
    Port:3306

    Example PHP Connection

    <?php
    $servername = "localhost";
    $username = "username_dbuser";
    $password = "your_password";
    $dbname = "username_dbname";
    
    // Create connection
    $conn = new mysqli($servername, $username, $password, $dbname);
    
    // Check connection
    if ($conn->connect_error) {
        die("Connection failed: " . $conn->connect_error);
    }
    echo "Connected successfully";
    ?>

    Managing Databases

    Deleting a Database

    1. Go to MySQL Databases in cPanel
    2. Find the database under "Current Databases"
    3. Click "Delete"
    4. Confirm deletion

    Deleting a User

    1. Go to MySQL Databases in cPanel
    2. Find the user under "Current Users"
    3. Click "Delete"
    4. Confirm deletion

    Changing User Password

    1. Go to MySQL Databases in cPanel
    2. Find the user under "Current Users"
    3. Click "Change Password"
    4. Enter new password
    5. Click "Change Password" to save

    Warning

    Deleting a database permanently removes all data. Always create a backup before deleting. If you change a user's password, update the password in all applications using that user.

    Troubleshooting

    Connection Refused

    • Verify database host is "localhost" (not an IP)
    • Check that the user is assigned to the database
    • Confirm username and password are correct
    • Check for typos in database name

    Access Denied

    • User may not have proper privileges - reassign with correct permissions
    • Password may be incorrect - try resetting it
    • Ensure username includes the cPanel prefix

    Database Size Limit

    • Check your hosting plan's database limits
    • Remove unnecessary data or optimize tables
    • Consider upgrading your hosting plan

    Best Practice

    Create separate database users for each application. This improves security by limiting access if one application is compromised. Regularly backup your databases using phpMyAdmin's export feature.