Guides /Hosting
Hosting

Managing MySQL Databases in cPanel: A Practical Guide

February 14, 20257 min readHostBible Team

Every WordPress site, and most PHP applications, runs on a MySQL database. If you host on a cPanel server, you manage those databases directly through cPanel's MySQL Database Wizard or the MySQL Databases tool. This guide walks through the full workflow: creating databases and users, connecting WordPress, running queries with phpMyAdmin, backing up and restoring, and troubleshooting the most common errors.

Step 1: Create a Database

In cPanel, scroll to the Databases section and open MySQL Databases. Under "Create New Database", enter a name, for example, mysite, and click Create Database. cPanel automatically prefixes the name with your account username, so it becomes something like user_mysite. Note the full prefixed name, you'll need it when configuring WordPress.

You can also use the MySQL Database Wizard which walks through each step in sequence. It's the quickest route if you're setting up a fresh WordPress install, since it combines database creation, user creation, and user assignment into a single guided flow without switching between sections.

Step 2: Create a Database User and Set a Password

A database needs a dedicated user with credentials your application uses to connect. Scroll to the "MySQL Users" section on the same page, enter a username and a strong password, then click Create User. Again, the username will be prefixed, e.g. user_wpuser.

Store the username and password somewhere secure immediately. cPanel won't show you the password again, and WordPress will need both at install time. If you lose the password, you can change it from MySQL Users in cPanel, but you'll then also need to update the password in your WordPress wp-config.php file to match.

Step 3: Assign the User to the Database

This is the step people most often miss, and it causes "Error Establishing a Database Connection" even when credentials look correct. Creating a user and creating a database are two separate actions. You must link them explicitly.

Scroll to "Add User To Database", select your user and your database from the dropdowns, then click Add. On the privileges screen, select ALL PRIVILEGES and click Make Changes. WordPress requires full privileges to create tables, run updates, and manage options. If you're setting up a third-party application with specific least-privilege requirements, consult its documentation for the exact permissions needed.

If you see a database connection error despite correct credentials in wp-config.php, come back to this step first, a user that hasn't been assigned to the database is the most common cause.

Connecting WordPress via wp-config.php

Open wp-config.php in your WordPress root directory and update these four lines:

define( 'DB_NAME',     'user_mysite' );
define( 'DB_USER',     'user_wpuser' );
define( 'DB_PASSWORD', 'YourStrongPassword' );
define( 'DB_HOST',     'localhost' );

The host is almost always localhost on shared cPanel hosting. A few hosts use a socket path instead, if your host documents a different DB_HOST value, use that. For 99% of standard cPanel setups, localhost is correct.

Using phpMyAdmin: Browse, Query, Export, and Import

phpMyAdmin is the graphical database interface bundled with cPanel. Access it from the Databases section. Select your database in the left panel to see its tables. From here you can:

  • Browse tables, click any table name to inspect rows. Useful for checking the wp_options table for site URL issues after a migration.
  • Run SQL queries, use the SQL tab for one-off queries, such as updating siteurl and home values in wp_options after a domain change.
  • Export a backup, select your database, click the Export tab, choose Quick format (SQL), and click Go. This downloads a .sql file you can keep as a backup or use to migrate.
  • Import a backup, select the target database, click Import, choose your .sql file, and click Go. Files larger than 50MB may hit PHP upload limits; use the cPanel Import tool in MySQL Databases for larger files or ask your host to increase the limit.

Running common WordPress database queries

Several routine WordPress tasks require direct database queries. These are the most common ones you'll encounter:

Updating site URL after migration:

UPDATE wp_options SET option_value = 'https://newdomain.com'
WHERE option_name IN ('siteurl', 'home');

Resetting a WordPress admin password:

UPDATE wp_users SET user_pass = MD5('newpassword')
WHERE user_login = 'admin';

For serialised data in wp_options (used by many plugins to store settings), avoid using raw SQL search-and-replace as it breaks serialisation. Use the WP-CLI command wp search-replace 'olddomain.com' 'newdomain.com' --all-tables or a tool like Better Search Replace which handles serialised data correctly.

Database backups: automating versus manual

For regular database backups, set up an automated schedule rather than relying on manual exports. The cPanel Backup Wizard can be configured to run weekly full backups to a remote FTP location. For daily granularity, most WordPress backup plugins (UpdraftPlus, BackWPup) can handle database-only backups on a daily schedule and store them in cloud storage.

A manual phpMyAdmin export before a significant change, a major plugin update, a theme swap, a database migration, is also good practice even if you have automated backups. Having a backup from five minutes before the change is more useful than one from last night if something goes wrong during the operation.

Store database backups off-server. A backup stored in public_html is accessible to anyone who finds the URL and is at risk if the server itself has a problem. Upload backups to S3, Backblaze B2, or Google Drive, or use a plugin that handles remote storage automatically.

WordPress Hosting That Just Works

HostBible WordPress plans include cPanel, phpMyAdmin, and automatic daily database backups, so you always have a clean restore point if something goes wrong.

View Hosting Plans