WordPress stores posts, pages, users, and settings in a MariaDB database on this account. The "Error establishing a database connection" page means PHP loaded, but WordPress could not sign in to that database. The site files are usually still there. The four values in wp-config.php (name, user, password, host) do not match what this account has, the user is not attached to the database, or the database itself is gone.
This article is for Beginner and Standard shared hosting (cPanel) in Australia. Open cPanel from the portal. Do not guess a hostname.
On a VPS you manage MariaDB yourself. Credentials and the console are on that server in the portal. See the VPS section below.
On a dedicated server, open a support ticket and we will walk you through access.
A new site should be installed with WordPress Toolkit or Installatron, not a zip from wordpress.org. Those tools create the database and write wp-config.php for you. See Install WordPress.
The site is unreachable in a different way (browser error, DNS, or a blank page)? Start with My website is down - what to check first or Fix the WordPress White Screen of Death / HTTP 500.
A step is unclear? Open a support ticket and we will help.
Open cPanel
- Sign in at the portal.
- Open the hosting service for the site.
- Click Log in to cPanel.
You do not need a server hostname to get in.
What usually causes it
On this hosting, the connection almost always fails for one of these reasons:
DB_NAMEorDB_USERis the short name you typed, not the full name with the account prefix (username_shop, notshop).- The password in
wp-config.phpis not the database user password (it is not your portal password). DB_HOSTis the website domain, an old host name, or an IP. Sites on this account must uselocalhost.- The user exists but was never added to the database, or privileges were removed.
- The database was deleted, or
wp-config.phpstill points at a database from a previous host after a move. wp-config.phpwas overwritten by a second install into the same folder.
cPanel still labels the tools MySQL. The engine is MariaDB. Every Beginner and Standard plan includes unlimited MariaDB databases. The site on this account connects with host localhost and port 3306.
Do not put the website domain in the host field. That sends the connection away from this account.
Check WordPress Toolkit or Installatron first
If Toolkit or Installatron already lists this install, open that tool before you edit files. It created the database and still knows the name.
WordPress Toolkit
- In cPanel, open WordPress Toolkit.
- Find the site.
- Note the database name it shows.
- Compare that name with MySQL Databases (steps below).
Installatron
- In cPanel, open Installatron.
- Open My Applications and choose the WordPress install.
- Note the database name stored for that application.
If Toolkit or Installatron does not list the site, use the file and MySQL Databases steps. You do not have to reinstall WordPress to fix a connection error.
Confirm the database still exists
- In the Databases section, open MySQL Databases.
- Under Current Databases, look for the full name (account username, then an underscore, then the short name).
- Under Current Users, confirm the database user is still there.
If the database is in the list, leave it. Do not create a second empty database "to be safe." An empty database will not bring the posts back.
If the database is missing, stop. Do not run a fresh WordPress install into the live folder. Hourly copies we keep include the databases on this account. Open a support ticket and ask us to restore that database. Tell us the domain, the full database name if you still have it (from wp-config.php), and the date you need. You can also export or restore a copy you already downloaded: Download and Restore a Backup.
Need a new database for a copy or a new app? Create a MySQL database and user. Use the full prefixed names in wp-config.php.
Read wp-config.php
The four defines live in wp-config.php in the site's document root, not inside wp-admin or wp-content.
- Open the File Manager.
- Go to the document root (
public_htmlfor the main domain, or the addon / subdomain folder). - Select
wp-config.phpand click Edit (or Code Editor). - If cPanel asks for a character encoding, leave utf-8.
- Find these lines:
define( 'DB_NAME', 'username_dbname' );
define( 'DB_USER', 'username_dbuser' );
define( 'DB_PASSWORD', 'the-password-you-set' );
define( 'DB_HOST', 'localhost' );
For a large download or a copy on your computer, use FTP. Edit in File Manager when you only need this one file.
Match the four values
Use the full names from MySQL Databases, not the short names you typed when you created them.
| Define | What it must be |
|---|---|
DB_NAME | Full database name, including the account prefix |
DB_USER | Full database username, including the account prefix |
DB_PASSWORD | The password for that database user |
DB_HOST | localhost |
- On MySQL Databases, copy the full database name from Current Databases.
- Copy the full username from Current Users.
- Put those strings into
DB_NAMEandDB_USER. Keep the quotes around each value. - Set
DB_HOSTtolocalhost. Remove a domain,127.0.0.1, or any leftover host from a previous provider. - If you are not sure the password is right, set a new one on MySQL Databases for that user, copy it, and paste it into
DB_PASSWORDin the same save. - Click Save Changes.
- Reload the site in a private window.
A second user can be attached to the same database. The user in wp-config.php is the one that must match.
Need a tool on your computer, or an app on another server, to reach this database? That is remote access, and localhost will not work for that tool. The WordPress site on this account should still use localhost. See Allow Remote MySQL Access.
Attach the user and grant privileges
A user that exists but is not attached cannot open the database.
- On MySQL Databases, scroll to Add User To Database.
- Choose the user from
DB_USER. - Choose the database from
DB_NAME. - Click Add.
- Tick ALL PRIVILEGES.
- Click Make Changes.
If the user is already listed next to the database, open the privileges for that pair and confirm ALL PRIVILEGES is ticked. WordPress needs at least SELECT, INSERT, UPDATE, DELETE, CREATE, ALTER, INDEX, and DROP.
Confirm the database opens in phpMyAdmin
If phpMyAdmin can open the database, MariaDB on this account is up and the database exists. The remaining problem is almost always wp-config.php.
- Open phpMyAdmin from the Databases section, or use the phpMyAdmin link next to the database on MySQL Databases.
- In the left sidebar, click the full database name.
- You should see WordPress tables (often prefixed
wp_:wp_options,wp_posts,wp_users).
No tables: this is an empty database, or you opened the wrong name. Do not import into it until you are sure. If the live tables are gone, open a support ticket and we will restore from the hourly copies.
phpMyAdmin signs you in through cPanel. There is no separate phpMyAdmin password. A failed WordPress connection does not mean phpMyAdmin is broken.
Do not delete wp-config.php
Do not remove wp-config.php to "run setup again." Visiting the site without that file starts the WordPress installer. Completing it against a new database gives you an empty site. Completing it against the existing database does not fix a bad password, and it can confuse a Toolkit or Installatron listing.
If the file is damaged or empty:
- Look in File Manager Trash in case you deleted it.
- If it is gone, open a support ticket and ask us to restore that file from the hourly copies. Tell us the domain and the path (
public_html/wp-config.php, or the addon / subdomain path). - You can also restore a copy you already downloaded. See Download and Restore a Backup.
If you just changed a password
Changing the database user password on MySQL Databases does not update wp-config.php. Change the define in the same session, save, then reload the site.
That password is not the WordPress admin login, and it is not your portal password, unless you set them the same. After a password change, update every app on this account that uses that user.
Disk and resource checks
If the four values are already correct and phpMyAdmin opens the tables, check that the account is not full. A full disk can stop writes and make the site fail in odd ways.
- Check disk usage.
- Open Resource Usage / Metrics. See Read your resource usage and metrics.
If a graph is against the plan limit, open a support ticket and we will look at the plan with you.
WordPress on a VPS
On a VPS the database is the MariaDB (or MySQL) instance you installed. Credentials and the console are on that server in the portal.
- Open
wp-config.phpon the VPS and confirmDB_NAME,DB_USER,DB_PASSWORD, andDB_HOST. - If MariaDB runs on the same VPS as the site,
DB_HOSTis usuallylocalhost. - Sign in with the console or SSH and confirm the database service is running and that user can connect.
Installing or securing the engine: Install MySQL or MariaDB and Secure It. Watching load: Monitor Server Resources.
Open a support ticket if you want us to walk through the service with you.
If the site still cannot connect
Work through this list once:
- Full prefixed
DB_NAMEandDB_USER, correctDB_PASSWORD,DB_HOSTislocalhost. - The user is attached to that database with ALL PRIVILEGES.
- phpMyAdmin opens the same database and shows the WordPress tables.
- You saved
wp-config.phpin the document root of this site, not a copy in another folder. - You reloaded in a private window.
If those are all true, open a support ticket. Include the domain and the full database name and username (not the password). We will look at the account with you.
Do not wait on an email thread.
Related
- Install WordPress
- Back Up and Migrate a WordPress Site
- Fix the WordPress White Screen of Death / HTTP 500
- Create a MySQL Database and User
- Manage a Database with phpMyAdmin
- Allow Remote MySQL Access
- Use the File Manager
- Create an FTP Account and Connect
- Download and Restore a Backup
- Check Disk Usage
- Read your resource usage and metrics
- Add an Addon Domain
- Create a Subdomain
- My website is down - what to check first
- Install MySQL or MariaDB and Secure It