WordPress : Error establishing database connection

If you’ve uploaded WordPress onto your hosting account and its getting the below error .

Error establishing database connection

Error establishing database connection

It might be that your Database credentials are incorrect in the wp-config.php file. To fix this problem, follow the instructions below:

  • FTP connect to your hosting account using your account FTP details , Or you can login to cPanel and access the File Manager.
  • Open the wp-config.php file (located in the webroot folder, in cPanel it would be the public_html folder)
  • Make sure your database name, username, password and hostname are correct (you can find instructions below depending on your hosting)
  • Find the database string below in the wp-config.php file and replace the relevant credentials with the correct information.
// ** Database settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define( 'DB_NAME', 'your-databas-ename' );

/** Database username */
define( 'DB_USER', 'your-datbase-username' );

/** Database password */
define( 'DB_PASSWORD', 'your-database-password' );

/** Database hostname */
define( 'DB_HOST', 'localhost' );

/** Database charset to use in creating database tables. */
define( 'DB_CHARSET', 'utf8' );

/** The database collate type. Don't change this if in doubt. */
define( 'DB_COLLATE', '' );
  • Re-upload the edited wp-config.php file

Cloud Hosting : Database credentials

To find your database name, hostname, username and password:

  1. Log into the Console
  2. Click the domain you want to manage
  3. Click Database and you will see your database under the Current Databases heading
  4. Click View under Credentials
  5. In the pop up you'll find log in information and your hostname

cPanel Hosting : Database credentials

  1. Log into the Console
  2. Click the domain you want to manage
  3. Click cPanel Hosting
  4. Under hosting settings, click Log into cPanel interface
  5. Under the Databases section click MySQL Databases
  6. On this page you’ll find the database name
  7. Scroll down to Current Users and your will find the database user which will connect to the database
  8. In the Current Users section you can reset your database user password

For cPanel users the hostname is always localhost

Success! You’ve done the steps for this article. If you’re unable to follow these steps, or receive an error in doing so, please submit a support request through your console or call us on 1300 638 734 for further assistance.