Developer · Guide
How to Create a Database for WordPress (cPanel, phpMyAdmin and MySQL)

Short answer
To create a database for WordPress, make an empty MySQL or MariaDB database, create a database user with a strong password, and give that user all privileges on the database. Then enter the database name, username, password and host, usually localhost, in the WordPress installer or wp-config.php.
Key takeaways
- WordPress needs one empty database, one user and full privileges.
- cPanel's MySQL Database Wizard does all three in one flow.
- Use utf8mb4 and a dedicated user, never the root account.
- The installer saves the details to wp-config.php.
- Connection errors almost always mean a wrong name, user, password or host.
What database does WordPress need?
WordPress stores all posts, pages, users, comments and settings in a MySQL or MariaDB database. Files such as images, themes and plugins live in folders, but everything you type into the dashboard ends up in database tables.
Each WordPress site needs three things before installation: an empty database, a database user, and that user's password with full rights on the database. You then give WordPress those details plus the database host.
The WordPress requirements page recommends a current MySQL 8 or MariaDB 10.11 or newer release. Older versions still run WordPress but no longer get security fixes.
If you are not sure which of the two your host uses, our comparison of MySQL vs MariaDB for WordPress explains the difference. For WordPress, both work the same way.
Many hosts create the database for you when you use a one-click installer. You only need to create one by hand for a manual install, a migration or a local test site.
Before you start: details you need to record
Write down four values as you go. WordPress asks for exactly these during setup, and they end up in the wp-config.php file.
| Setting | What it is | Typical example |
|---|---|---|
| Database name | The empty database you create | mysite_wp |
| Database username | The account WordPress logs in with | mysite_wpuser |
| Database password | A long, unique password for that user | Generated by your panel |
| Database host | The server address of the database | localhost |
Use a strong, generated password. WordPress stores it in a file on the server, so you never need to type it again, and a weak one is an easy target.
Keep the four values in a password manager rather than a text file on your desktop. You will need them again if you move hosts, restore a backup or connect a staging copy of the site.
On shared hosting, the panel usually adds your account name as a prefix to the database and user names. Copy the full names exactly as shown, prefix included.
Method 1: Create a database in cPanel
Most shared hosts use cPanel, which has a guided MySQL Database Wizard. It creates the database, the user and the permissions in one flow.
Log in to cPanel and open Databases > MySQL Database Wizard. Type a short name for the database and click Next Step.
Enter a username and click the password generator. Save the generated password somewhere safe, then click Create User.
On the privileges screen, tick All Privileges and click Next Step. WordPress needs full rights on its own database to create tables and run updates.
The wizard then confirms the database and user. Use “localhost” as the host unless your provider's documentation gives a different address.
If you skip the wizard, you can do the same work on the main MySQL Databases page. Create the database at the top, add a user further down, then use the “Add User to Database” section to link them with all privileges.
Method 2: Create a database in other hosting panels
Plesk, DirectAdmin, hPanel and custom dashboards follow the same idea with different labels. Look for a section called Databases or MySQL Databases.
Create a new database, add a user, set a password and assign that user to the database with all permissions. Some panels do all of this on one screen.
Managed WordPress hosts may hide database creation entirely, since they create it when you add a site. In that case, their dashboard usually shows the credentials or offers phpMyAdmin access instead.
If the host gives a remote database server, it will list a hostname such as a private IP or a domain. Use that value instead of localhost.
Method 3: Create a database with phpMyAdmin
phpMyAdmin is a web interface for MySQL. Many hosts and local tools include it, and it works when your panel has no database wizard.
Open phpMyAdmin and click the Databases tab. Enter a database name, choose the utf8mb4_unicode_ci collation and click Create.
Next, open the User accounts tab and click Add user account. Enter a username, set the host to localhost, generate a password and save it.
Under “Database for user account”, choose to grant all privileges on the database you just made, then click Go. On some shared hosts, phpMyAdmin cannot create users, so make the user in your hosting panel instead.
Method 4: Create a database from the command line
On a VPS or dedicated server, the command line is the fastest route. Log in to the MySQL or MariaDB shell as an administrator, usually the root user.
Run the following commands, replacing the names and the password with your own values.
CREATE DATABASE wordpress CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'use-a-long-random-password';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;
The first line creates the database with the utf8mb4 character set, which supports every language and emoji. The MySQL CREATE DATABASE reference explains each option in full.
The second and third lines create a user that can log in only from the same server and give it rights on this database alone. The official WordPress guide to creating a database uses the same pattern.
Never let WordPress use the root account. A dedicated user limits the damage if the site is ever compromised, because it can touch only its own database.
After running the commands, test the new account by logging in with it from the shell. If the login works and the user can see the new database, WordPress will be able to connect with the same details.
Method 5: Create a database for a local WordPress site
Local development tools usually handle databases for you. Apps such as Local, DevKinsta and WordPress Studio create a database every time you add a site.
If you run your own stack, such as XAMPP or MAMP, open the bundled phpMyAdmin and follow Method 3. Local stacks often use root with no password, which is acceptable only on your own computer.
Our guide to setting up a local WordPress development environment compares the main tools and their database defaults.
Connect the database to WordPress
With the database ready, upload WordPress and visit your domain. The installer asks for the database name, username, password, host and table prefix.
Enter the values you recorded and click Submit. If they are correct, WordPress writes them to wp-config.php and moves on to the site title and admin account.
You can also edit the file yourself. Copy wp-config-sample.php to wp-config.php and fill in DB_NAME, DB_USER, DB_PASSWORD and DB_HOST, as described in the wp-config.php documentation.
Not sure where that file lives? Our guide on finding wp-config.php in WordPress shows its location on common hosts.
Change the default “wp_” table prefix if you like, especially when several sites share one database. Each site then needs its own unique prefix.
Fix common database setup errors
The most common problem is the message “Error establishing a database connection”. It almost always means one of the four values is wrong.
Check the database name and username for a missing account prefix, re-enter the password, and confirm the host. Our guide to fixing the database connection error walks through each check.
If the installer says it cannot write wp-config.php, the folder permissions are too strict. Create the file by hand or see our fix for being unable to write to wp-config.php.
An “access denied” message usually means the user was created but never given privileges on the database. Go back and grant all privileges, then try again.
A blank page or a request to repair tables after setup points to a different problem, such as damaged tables from an interrupted import. In that case, restore the import or use the built-in repair tool before going further.
Keep your WordPress database healthy
Once the site is live, the database grows with every revision, comment and plugin setting. Back it up before updates and at regular intervals.
Our guide on backing up a WordPress database covers manual exports and plugin backups.
Over time, clear old revisions, spam comments and expired transients. Our tips to optimise the WordPress database keep queries quick without risking your content.
Frequently asked questions
Does WordPress create its own database?
No. WordPress creates its tables, but the empty database and user must already exist. One-click installers on most hosts do this step for you behind the scenes.
What should I use as the database host?
Use localhost on most shared hosts and servers where the database runs on the same machine. Some providers use a separate database server and list a different hostname in their dashboard.
Can two WordPress sites share one database?
Yes, as long as each site uses a different table prefix in wp-config.php. Separate databases are still easier to back up, move and secure, so use them when your host allows.
Which collation should a WordPress database use?
Use utf8mb4 with utf8mb4_unicode_ci or a newer utf8mb4 collation. This supports all languages and emoji, which older utf8 settings cannot store fully.
How many privileges does the WordPress database user need?
Grant all privileges on the WordPress database only. WordPress and plugins need to create and change tables during updates, but the user should have no rights on other databases.
Sources
- Creating database for WordPress WordPress Developer Resources
- Requirements WordPress.org
- MySQL Database Wizard cPanel Documentation
- CREATE DATABASE Statement MySQL Reference Manual
- Editing wp-config.php WordPress Developer Resources
Is your product missing, or something out of date?
Tell us what to add or correct. We read every note and reply when we need a source. A message does not buy a ranking.
Thanks — we review requests within 3 business days.
Related guides
About the editors
Researched from the primary sources listed above and checked against our editorial rules before publishing.


