To create and manage MySQL databases, use the MySQL Databases interface in cPanel. This tool allows you to create new databases, add database users, assign privileges, and perform maintenance tasks like checking or repairing databases. For first-time setup, the MySQL Database Wizard provides a step-by-step process that automatically creates a database, user, and assigns permissions in one workflow.
Creating Your First MySQL Database
The MySQL Database Wizard is the recommended method for creating your first database and user. This tool guides you through the entire process in three simple steps. To access it, navigate to cPanel > Home > Databases > MySQL Database Wizard. The wizard automatically handles user creation and privilege assignment, making it ideal for beginners or quick setups.
For more advanced database management after your initial setup, use the standard MySQL Databases interface, which provides greater flexibility for managing multiple databases and users simultaneously.
Creating a Database Manually
To create a new MySQL database through the main interface, follow these steps:
- Navigate to cPanel > Home > Databases > MySQL Databases
- In the New Database text box, enter a name for your database
- Click Create Database
- Click Go Back to return to the main interface
Your new database will appear in the Current Databases table. The database name can contain up to 64 characters. If database prefixing is enabled on your hosting account, your username and an underscore will automatically prepend to the database name, reducing the available characters to 63.
Important Database Naming Rules
Keep these character limits in mind when naming your database:
- Maximum database name length: 64 characters
- Each underscore character counts as two characters toward this limit
- With database prefixing enabled: 63 characters maximum (including the prefix and underscore)
- Additional underscores require two more characters each
Creating and Managing Database Users
After creating a database, you need to create at least one user and assign privileges. Database users are separate accounts that applications use to access and modify database content. Each user can have different permission levels, allowing you to control what operations they can perform.
To create a new database user, locate the MySQL Users section in the same interface. Enter a username and password, then click Create User. After creating the user, scroll to the Add User To Database section to assign the user to your database and set their privileges.
Managing Database Privileges
Database privileges control what actions a user can perform. Common privilege levels include:
- ALL PRIVILEGES: Complete control over the database
- SELECT: Read data from tables
- INSERT: Add new records to tables
- UPDATE: Modify existing records
- DELETE: Remove records from tables
- CREATE: Create new tables or databases
- DROP: Delete tables or databases
For most applications, granting ALL PRIVILEGES is appropriate. However, for security-sensitive environments, you may want to assign only the minimum privileges required for your application to function.
Using phpMyAdmin for Database Management
Once you've created a database and user through cPanel, use phpMyAdmin to manage the database content, run queries, import data, and perform other database operations. Access phpMyAdmin through cPanel > Home > Databases > phpMyAdmin.
Important: Always create databases and database users through the cPanel MySQL Databases interface, not through phpMyAdmin. phpMyAdmin does not properly map databases to your cPanel account, which can cause backup and restoration failures. Use phpMyAdmin only for managing existing database content and running queries.
Database Maintenance and Troubleshooting
If you experience problems with a database, use the maintenance tools in the MySQL Databases interface to check for and repair errors.
Checking a Database for Errors
To check a database for errors:
- Scroll to the Modify Databases section
- In the Check Database dropdown menu, select your database
- Click Check Database
- Review the results displayed on the following screen
The system will scan all tables in the selected database and report any errors or corruption. If errors are found, you can use the repair function to attempt automatic fixes.
Repairing a Database
To repair a database that has errors:
- In the Repair Database dropdown menu, select the problematic database
- Click Repair Database
- Wait for the repair process to complete
- Review the repair results
Database repairs can fix many common issues, including table corruption, index problems, and structural inconsistencies. However, severe corruption may require restoring from a backup.
Remote MySQL Connections
If your hosting configuration includes a remote MySQL server, you'll see a Remote MySQL Host section in the interface. This section displays the hostname or IP address you should use when configuring applications to connect to your database from external servers or local development environments.
By default, MySQL servers only accept connections from localhost for security reasons. To enable remote connections to your database, you'll need to configure remote MySQL access through the Remote MySQL interface in cPanel, where you can authorize specific IP addresses to connect to your databases.
Deleting Databases and Users
To delete a database, locate it in the Current Databases table and click the Delete button next to the database name. To remove a database user, find them in the Current Users table and click Delete.
Warning: Deleting a database or user is permanent and cannot be undone. All data in a deleted database will be lost. Always create a backup before deleting databases, especially if they contain production data.
Best Practices for MySQL Database Management
Follow these best practices to maintain secure and efficient databases:
- Use strong, unique passwords for all database users
- Grant only the minimum privileges required for each user
- Regularly backup your databases before making significant changes
- Monitor database size and optimize tables periodically
- Delete unused databases and users to reduce security risks
- Use meaningful names for databases and users to simplify management
- Test database operations in a development environment before implementing in production
Frequently Asked Questions
How many MySQL databases can I create in my hosting account?
The number of MySQL databases you can create depends on your hosting plan. Most shared hosting plans at OBHost allow multiple databases, while higher-tier plans typically offer unlimited databases. Check your plan details or contact support@obhost.org to confirm your account's database limit.
Why can't I see my database in phpMyAdmin after creating it?
If your database doesn't appear in phpMyAdmin immediately after creation, try logging out of phpMyAdmin and logging back in. The interface caches the database list, and refreshing your browser may not update it. If the database still doesn't appear, verify it exists in the cPanel MySQL Databases interface and check that you're viewing the correct server if multiple database servers are configured.
What should I do if my database becomes corrupted?
First, use the Check Database function to confirm the corruption. If errors are found, use the Repair Database tool to attempt automatic repairs. If the repair fails or if you lose data, restore from your most recent backup. To prevent future corruption, ensure your applications close database connections properly and avoid server crashes during database operations.
Can I rename an existing MySQL database?
MySQL does not support direct database renaming through cPanel. To rename a database, you must create a new database with the desired name, export the data from the old database using phpMyAdmin, import it into the new database, update your application configuration files to use the new database name, and then delete the old database. Always backup your data before performing this process.
For additional assistance with MySQL database management, the OBHost support team is available 24/7. Visit https://www.obhost.net/contact or email support@obhost.org for help with any database-related questions or issues.