In this guide
- understand databases, users and privileges, and cPanel’s name prefix;
- create a database and user with the Database Wizard;
- manage them afterwards, and connect from PHP;
- create tables, import and export in phpMyAdmin;
- back up your databases.
A site made only of HTML pages, like the page template in these guides, doesn’t need a database. If you install WordPress with cPanel’s installer, it creates the database for you.
Three parts: database, user, privileges
- The database — a container of tables. Each table is like a spreadsheet: columns (name, email, date) and a row for each record.
- The database user — a username and password your website uses to connect. It’s separate from your cPanel login and from any email account.
- Privileges — what that user is allowed to do in that database: read, add, change, delete, create tables. A user can reach nothing until it’s been added to a database.
cPanel hosting uses MariaDB or MySQL. They work the same way for everything in this guide, and cPanel and phpMyAdmin call them both “MySQL”.
Create a database with the Database Wizard
Open cPanel Databases Database Wizard (called MySQL® Database Wizard on older versions of cPanel).
Create a database. Type a short name that says what it’s for —
site,shop,bookings— and select Next Step.Create a database user. Type a username (letters and numbers only), select Password Generator, tick that you’ve copied the password somewhere safe, and select Create User. You’ll need this password in your website’s settings; you won’t see it again.
Add the user to the database. Tick ALL PRIVILEGES — that’s what WordPress and most applications need on their own database — and select Next Step.
Done. Write down the full database name and full username shown on the final screen.
The four details your website needs
| Setting | What to enter | Example |
|---|---|---|
| Database host | localhost — the database is on the same server as your site | localhost |
| Database name | The full name, with prefix | mybusin_shop |
| Username | The full user name, with prefix | mybusin_shopuser |
| Password | The database user’s password | (from the Password Generator) |
In WordPress these go in wp-config.php as DB_HOST, DB_NAME, DB_USER and DB_PASSWORD.
Manage databases and users
cPanel Databases Manage My Databases (MySQL® Databases on older versions) does everything the wizard does, on one page, and is where you come back later to:
- Change a user’s password — under Current Users, select Change Password. Remember to update your website’s settings straight away, or it will lose its connection.
- Give a user access to another database — under Add User to Database, choose both and select Add, then pick the privileges.
- Change privileges — under Current Databases, select the user’s name next to the database.
- Check or repair a database after an error message mentions a “crashed” table.
- Delete a database or user you no longer need. Deleting a database can’t be undone — download a backup first.
Which privileges?
| The user is for… | Tick |
|---|---|
| WordPress, a shop, or your own site that creates its own tables | ALL PRIVILEGES |
| A site that only reads, adds and changes data in tables you’ve already made | SELECT, INSERT, UPDATE, DELETE |
| A reporting tool that should only read | SELECT |
Connect to your database from PHP
If you’re writing your own PHP, connect with PDO and keep the password in a file outside public_html, so it can never be downloaded even if PHP fails. Your home folder (one level above public_html) is the place for it.
<?php
// /home/mybusin/config/database.php — outside public_html
return [
'dsn' => 'mysql:host=localhost;dbname=mybusin_shop;charset=utf8mb4',
'user' => 'mybusin_shopuser',
'pass' => 'the-generated-password',
];<?php
declare(strict_types=1);
$config = require dirname(__DIR__) . '/config/database.php';
$db = new PDO($config['dsn'], $config['user'], $config['pass'], [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, // stop on errors
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES => false,
]);
// Always use prepared statements with placeholders for anything a visitor typed.
$find = $db->prepare('SELECT name, email FROM customers WHERE email = ?');
$find->execute([$_GET['email'] ?? '']);
$customer = $find->fetch();More examples — reading, searching, adding, changing and deleting rows, transactions, and a searchable, sortable, paged table — are in PHP and MySQL with PDO.
Work inside a database with phpMyAdmin
Open cPanel Databases phpMyAdmin. It opens already logged in, with your databases listed on the left. Select one to see its tables, then a table to see its rows.
Create a table
You can use the Create new table form, but it’s often quicker and clearer to paste SQL into the SQL tab. Select your database first, then run:
CREATE TABLE enquiries (
id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100) NOT NULL,
email VARCHAR(255) NOT NULL,
message TEXT NOT NULL,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
INDEX (email)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;Use utf8mb4 so names, accents and emoji are stored correctly, and InnoDB, which is safer if the server stops mid-write.
Import a database
Moving a site from another host? Export its database there as a .sql file, create an empty database and user here with the wizard, then in phpMyAdmin select the new database, open Import, choose the file and select Import. Large imports may hit the upload limit shown on the page; compress the file as .sql.gz or .zip, or ask OnPoint support to import it for you.
Export a database
Select the database, open Export, leave Quick and SQL selected and select Export. You get a .sql file you can keep as a backup or import elsewhere.
Back up your databases
A website’s files and its database are backed up separately. In cPanel Files Backup, under Download a MySQL Database Backup, select a database name to download a compressed copy, and restore it on the same page if you ever need to. Do this before upgrades, plugin changes or PHP version changes, and keep copies somewhere other than the server. OnPoint’s website backup add-on can do it automatically.
Remote database access
cPanel Databases Remote Database Access lets a computer elsewhere — a desktop database tool, or an app on another server — connect directly. Leave it empty unless you need it, and if you do, add only your own fixed IP address, never % (which means “anyone”).
Troubleshooting
| Error | Usual cause |
|---|---|
| “Error establishing a database connection” (WordPress) | The name, user or password in wp-config.php is wrong — check the prefix — or the user hasn’t been added to the database. |
| “Access denied for user” | Wrong password, or the user doesn’t have privileges on that database. Re-add it in Manage My Databases. |
| “Unknown database” | The database name is missing its username_ prefix. |
| Import stops or times out | The file is too large for an upload — compress it, or ask support to import it. |
Odd characters such as é | The data was saved or imported with the wrong character set. Use utf8mb4 throughout. |