Every dynamic website - WordPress, a shop, a custom application - keeps its content in a MySQL database. cPanel gives you four tools for this, under the Databases section: Database Wizard, Manage My Databases, phpMyAdmin and Remote Database Access. This guide covers creating a database properly, connecting to it, maintaining it, and the prefix mistake that causes most connection failures.

The one thing to know before you start. cPanel automatically prefixes every database and database user with your account name. Type shop and the real name becomes something like mysite_shop. Your application configuration must use the full prefixed name. "Access denied for user" is nearly always this.

Creating a database with the Database Wizard

The wizard is the right tool because it will not let you forget to attach a user to the database - the most common way to create a database that nothing can connect to.

  1. Log in to cPanel from My Products & Services.
  2. Under Databases, open Database Wizard.
  3. Step 1 - enter a database name. Keep it short and descriptive; the prefix is added for you. Click Next Step.
  4. Step 2 - enter a username and use Password Generator. Copy both the full username and the password somewhere safe now; the password is not shown again. Click Create User.
  5. Step 3 - tick ALL PRIVILEGES, then Next Step.
  6. cPanel confirms the full database name and full username. Note both down.

Your connection details are then:

Setting Value
Database hostlocalhost - not your domain, not an IP address
Database nameThe full prefixed name, e.g. mysite_shop
UsernameThe full prefixed username, e.g. mysite_shopuser
PasswordThe one you generated in Step 2
Port3306 (rarely needs specifying)

Manage My Databases: the everyday screen

Databases → Manage My Databases is where you go afterwards. From here you can:

  • See every database, its size, and which users are attached to it.
  • Add an existing user to another database, or change their privileges.
  • Rename a database or a user.
  • Change a user's password - remember to update your application's configuration file at the same time, or the site goes down immediately.
  • Repair or check a database that is behaving oddly.
  • Delete a database or user.
Deleting a database is instant and permanent. There is no confirmation beyond the dialog and no undo. Download a copy from Files → Backup first - it takes fifteen seconds and has saved a great many websites.

phpMyAdmin: looking inside

Databases → phpMyAdmin opens the database itself. You are logged in automatically. Use it to:

  • Browse and edit data - select a database on the left, then a table, then Browse.
  • Run SQL - the SQL tab. Always run a SELECT first to see what a query matches before turning it into an UPDATE or DELETE.
  • Export - the Export tab, Quick method, SQL format, gives you a portable dump.
  • Import - the Import tab, for restoring a dump or moving a site in.
  • Optimise - select all tables in the Structure view and choose Optimize table to reclaim space after large deletions.

Resetting a lost WordPress admin password

A genuinely useful trick when you are locked out of your own site:

  1. Open phpMyAdmin and select your WordPress database.
  2. Open the users table (it may carry a custom prefix such as hv7x_users).
  3. Click Edit on your user row.
  4. In the user_pass row, type your new password in the Value box and select MD5 from the Function dropdown.
  5. Click Go, then log in and change it again from inside WordPress.

Remote Database Access

By default the database only accepts connections from the server itself, which is the correct and secure default. Databases → Remote Database Access lets you add specific IP addresses that may connect from outside - useful for a desktop tool such as MySQL Workbench, or an external application.

Add individual addresses only. Never add %, which permits connections from the entire internet and exposes your database to automated attacks. Remember that most home and office connections have a dynamic IP that changes, so remove entries when you are finished with them.

Keeping databases healthy

Task How often Why
Export a dumpBefore every changeThe only reliable undo.
Clear post revisions and expired transientsMonthlyBloat makes every query slower and raises IOPS.
Optimize tablesAfter bulk deletionsReclaims disk space that deletion alone does not free.
Check database sizeQuarterlySudden growth usually means a logging plugin nobody is reading.
Remove unused databasesYearlyOld staging copies hold real customer data and are rarely patched.

Troubleshooting

Symptom Cause and fix
"Error establishing a database connection" Check all four values in your config file. The usual culprit is a missing account prefix on the database or user name.
"Access denied for user" The user exists but is not attached to that database, or has no privileges. Fix it in Manage My Databases with ALL PRIVILEGES.
"Unknown database" The name in your config does not match. Compare it character for character with the list in Manage My Databases.
Import fails on "table already exists" Drop the existing tables in phpMyAdmin first, or add DROP TABLE IF EXISTS statements to the dump.
Import exceeds the upload size limit Use Files → Backup → Restore a MySQL Database Backup instead, which is not bound by the browser upload limit. Gzipping the .sql file also helps.
Import stops part-way with no error It hit the execution time limit. Split the dump, or ask Technical Support to import it server-side.
Site slow, admin area slowest of all Database bloat driving IOPS up. Clean revisions and transients, then optimise the tables.
Table marked as crashed Use Repair Database in Manage My Databases. If it will not repair, restore from your most recent dump.
Cannot connect remotely Your current public IP is not in Remote Database Access, or it changed since you added it.

Frequently asked questions

How many databases can I create?

It depends on your plan - the Ultimate plan is unlimited, and your current count and allowance are shown in the Statistics panel on the cPanel home screen.

Should the database host be my domain name?

No. Use localhost. The application and the database run on the same server, and using the domain forces an unnecessary network round trip that may be refused.

Can two websites share one database?

They can if they use different table prefixes, but it is a bad idea. Separate databases mean you can back up, restore, move or delete one site without touching the other.

What character set should I use?

utf8mb4 with utf8mb4_unicode_ci. It handles every language plus emoji correctly. Modern applications set this themselves.

Do databases count towards my disk usage?

Yes. The cPanel Statistics panel shows Database Disk Usage separately so you can see how much of your total it accounts for.

Can Fast Hive import a very large database for me?

Yes. Upload the dump to your home directory and open a ticket with Technical Support naming the file and the target database. Server-side imports are not subject to browser or execution time limits.

Database problem? Open a ticket with Technical Support at My Support Tickets with the domain, the database name and the exact error text. Never include the database password - we can see the account without it.
Cette réponse était-elle pertinente ? 0 Utilisateurs l'ont trouvée utile (0 Votes)

Powered by WHMCompleteSolution