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
- Log into your cPanel account
- Navigate to the "Databases" section
- Click on "MySQL Databases"
Step 2: Create New Database
- In the "Create New Database" section, enter your database name
- Database names are prefixed with your cPanel username (e.g., username_dbname)
- 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
- Scroll down to "Add New User" section
- Enter a username (will be prefixed with your cPanel username)
- Enter a strong password or use the Password Generator
- 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
- Scroll to "Add User To Database" section
- Select the user from the dropdown menu
- Select the database from the dropdown menu
- 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:
- In cPanel, go to "Databases" section
- Click "phpMyAdmin"
- Select your database from the left sidebar
- 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:
localhostusername_dbnameusername_dbuseryour_password3306Example 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
- Go to MySQL Databases in cPanel
- Find the database under "Current Databases"
- Click "Delete"
- Confirm deletion
Deleting a User
- Go to MySQL Databases in cPanel
- Find the user under "Current Users"
- Click "Delete"
- Confirm deletion
Changing User Password
- Go to MySQL Databases in cPanel
- Find the user under "Current Users"
- Click "Change Password"
- Enter new password
- 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.
