When to use this
Most PHP applications store their content in a database: WordPress, Joomla, Laravel apps, billing and inventory tools. Create one when you install such an app by hand, restore a backup, or move a site from another host. A database needs three things: the database, a user with a password, and privileges that link them.
ODHOST note: Database limits depend on your plan: Spark 5, Boost 25, Thrive 40, Turbo 80, Elite unlimited. Compare them on the shared hosting plans page.
Create a database with the wizard
Menus vary by cPanel version and host configuration; on most servers the path is below.
- Open Databases > MySQL Database Wizard in cPanel.
- Type a short database name such as
shopand click Next Step. cPanel creates it ascpanelusername_shop. - Enter a username such as
shopuser. It becomescpanelusername_shopuser. - Click Password Generator, copy the generated password to a password manager, and click Create User.
- Tick ALL PRIVILEGES on the next screen, then click Next Step. Most apps need full privileges on their own database to install and update tables.
- Note the three values on the success screen: full database name, full username and the password you saved.
You can do the same in separate steps on the Databases > MySQL Databases page, which is also where you later change passwords, add users to databases, or delete them.
Connect your app to the database
On cPanel hosting the database normally runs on the same server as your website, so the host is localhost. For WordPress, the lines in wp-config.php look like this:
define( 'DB_NAME', 'cpanelusername_shop' );
define( 'DB_USER', 'cpanelusername_shopuser' );
define( 'DB_PASSWORD', 'the-password-you-saved' );
define( 'DB_HOST', 'localhost' );
For a Laravel or similar app, the .env file uses the same values:
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=cpanelusername_shop
DB_USERNAME=cpanelusername_shopuser
DB_PASSWORD=the-password-you-saved
Installing WordPress by hand? Our WordPress install guide for cPanel walks through the full process.
Import existing data with phpMyAdmin
- Open Databases > phpMyAdmin.
- Select your new database in the left column.
- Click the Import tab, choose your
.sqlor.sql.gzfile, and click Import (the button may say Go in older versions). - Check that the tables appear in the left column.
Very large files may exceed the upload limit. Use cPanel's Restore a MySQL Database Backup option described in restoring a backup in cPanel, or ask support.
Good habits for databases
- Use one database and one user per application. If one site is compromised, the others stay protected.
- Give each user a unique generated password, stored in a password manager rather than in emails or chat.
- Delete databases and users left behind by old test installs, so they do not count against your plan limit or hold stale customer data.
- Download a database backup before every major update or plugin change.
How to confirm it worked
- In MySQL Databases, the database lists your user under "Privileged Users".
- phpMyAdmin shows the database and, after an import, its tables.
- Your app installs or loads without a database error.
If your site shows "Error establishing a database connection", follow the database connection fix.
If it still fails
Open a support ticket and include:
- The full database name and username (never the password)
- The app you are connecting and the exact error message
- The size of any file you tried to import and the error phpMyAdmin showed
- The time of the attempt (IST)
Frequently asked questions
Why does cPanel add my username to the database name?
cPanel prefixes database and user names with your cPanel username and an underscore so names never clash between accounts on the same server. Always use the full prefixed name in your app.
How many databases can I create?
It depends on your plan. ODHOST Spark includes 5 databases, Boost 25, Thrive 40, Turbo 80, and Elite unlimited.
Can I connect to the database from my own computer?
Only if remote database access is enabled for your account and your IP is allowed in cPanel's Remote Database Access page. Ask support if the page is missing; otherwise use phpMyAdmin.
Is it MySQL or MariaDB?
cPanel servers run either MySQL or MariaDB, and cPanel calls both "MySQL" in its menus. phpMyAdmin's home page shows the exact server type and version.