Almost every dynamic website (WordPress, Joomla, Laravel, online shops) stores its content in a MySQL or MariaDB database. In cPanel a database and a database user are separate objects: you create both and then link them with privileges. This guide covers the full lifecycle in MySQL Databases. For a guided one-page setup use the MySQL Database Wizard instead.
Before you start
- Access to cPanel.
- Know that cPanel adds your account name as a prefix. If your cPanel user is
mdmuserand you typeshop, the real name ismdmuser_shop. Use the full name in your application.
Create a database
- Open cPanel → Databases → MySQL Databases.
- Under Create New Database, type a short name such as
shop. - Click Create Database, then Go Back.
Create a database user
- On the same page, scroll to MySQL Users → Add New User.
- Enter a Username (it also gets the prefix).
- Enter a strong password or use the Password Generator, and copy it somewhere safe.
- Click Create User.
Add the user to the database and grant privileges
- Under Add User To Database, select the user and the database, then click Add.
- On the Manage User Privileges page, tick ALL PRIVILEGES for a normal web application, or tick only the ones you need (for example
SELECTfor a read-only reporting user). - Click Make Changes.
Your application now connects with host localhost, the full database name, the full username and the password.
Tip: Use one user per application. If one site is compromised, the attacker cannot read your other databases.
Change privileges or a user password
- In Current Databases, click the username under Privileged Users to edit its privileges.
- In Current Users, click Change Password next to the user. Update the password in your application's config file (for WordPress,
wp-config.php) straight away.
Rename a database
- In Current Databases, click Rename next to the database.
- Enter the new name and click Proceed.
- Update the database name in your application's configuration.
Warning: Renaming copies the data into a new database and drops the old one. On large databases it can take time and the site will show database errors until the config is updated. Take a backup first.
Delete a database or user
- Export a backup first with phpMyAdmin or cPanel → Files → Backup.
- In Current Databases, click Delete next to the database and confirm. This cannot be undone from cPanel.
- Remove unused users in Current Users with Delete.
Troubleshooting
- Access denied for user: the user is not added to the database, or the password in your config is wrong. Re-add the user with ALL PRIVILEGES and reset the password.
- Unknown database: you used the short name; include the account prefix.
- Connecting from your own computer: allow your IP in Remote MySQL.
