{"id":3948,"date":"2026-08-04T09:33:00","date_gmt":"2026-08-04T08:33:00","guid":{"rendered":"https:\/\/www.4uhosting.co.uk\/articles\/knowledgebase\/fix-wordpress-error-establishing-a-database-connection\/"},"modified":"2026-08-19T14:00:24","modified_gmt":"2026-08-19T13:00:24","slug":"fix-wordpress-error-establishing-a-database-connection","status":"publish","type":"kb_article","link":"https:\/\/www.4uhosting.co.uk\/articles\/knowledgebase\/fix-wordpress-error-establishing-a-database-connection\/","title":{"rendered":"Fix WordPress Error Establishing a Database Connection"},"content":{"rendered":"<p>If WordPress cannot connect to its database, you may see this message:<\/p>\n<p><code>Error establishing a database connection<\/code><\/p>\n<p>This usually means the database name, database username, password or host in <code>wp-config.php<\/code> does not match the database details on the hosting account.<\/p>\n<p>Take a backup before editing WordPress files.<\/p>\n<ol>\n<li>Log in to cPanel.<\/li>\n<li>Open <strong>File Manager<\/strong>.<\/li>\n<li>Open the folder where WordPress is installed.<\/li>\n<li>Find the <code>wp-config.php<\/code> file.<\/li>\n<li>Right-click the file and choose <strong>Edit<\/strong>.<\/li>\n<li>Look for these lines:<\/li>\n<\/ol>\n<pre><code>define( 'DB_NAME', 'database_name_here' );\ndefine( 'DB_USER', 'username_here' );\ndefine( 'DB_PASSWORD', 'password_here' );\ndefine( 'DB_HOST', 'localhost' );<\/code><\/pre>\n<ol>\n<li>Check that the database name matches the database used by the WordPress site.<\/li>\n<li>Check that the database username is correct.<\/li>\n<li>Check that the database password is correct.<\/li>\n<li>Check that the database host is correct. On most cPanel hosting accounts this is usually <code>localhost<\/code>.<\/li>\n<li>Save the file if you make any changes.<\/li>\n<li>Reload the website.<\/li>\n<\/ol>\n<p>You can check database names and database users in cPanel under <strong>MySQL Databases<\/strong>.<\/p>\n<p>Database passwords cannot normally be viewed after they have been set. If you do not know the database user&#8217;s password, you may need to set a new one in cPanel and then update <code>DB_PASSWORD<\/code> in <code>wp-config.php<\/code>.<\/p>\n<p>You may also see a line like this:<\/p>\n<pre><code>$table_prefix = 'wp_';<\/code><\/pre>\n<p>Do not change the table prefix unless you know it is wrong. If the table prefix does not match the database tables, WordPress may behave as though the site has no content.<\/p>\n<p>If the error continues after checking the details, open a support ticket and include the domain name and the error message you are seeing.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If WordPress cannot connect to its database, you may see this message: Error establishing a database connection This usually means the database name, database&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"template":"","kb_category":[37],"class_list":["post-3948","kb_article","type-kb_article","status-publish","hentry","kb_category-wordpress"],"_links":{"self":[{"href":"https:\/\/www.4uhosting.co.uk\/articles\/wp-json\/wp\/v2\/kb_article\/3948","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.4uhosting.co.uk\/articles\/wp-json\/wp\/v2\/kb_article"}],"about":[{"href":"https:\/\/www.4uhosting.co.uk\/articles\/wp-json\/wp\/v2\/types\/kb_article"}],"author":[{"embeddable":true,"href":"https:\/\/www.4uhosting.co.uk\/articles\/wp-json\/wp\/v2\/users\/1"}],"version-history":[{"count":1,"href":"https:\/\/www.4uhosting.co.uk\/articles\/wp-json\/wp\/v2\/kb_article\/3948\/revisions"}],"predecessor-version":[{"id":4033,"href":"https:\/\/www.4uhosting.co.uk\/articles\/wp-json\/wp\/v2\/kb_article\/3948\/revisions\/4033"}],"wp:attachment":[{"href":"https:\/\/www.4uhosting.co.uk\/articles\/wp-json\/wp\/v2\/media?parent=3948"}],"wp:term":[{"taxonomy":"kb_category","embeddable":true,"href":"https:\/\/www.4uhosting.co.uk\/articles\/wp-json\/wp\/v2\/kb_category?post=3948"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}