{"id":1584,"date":"2019-02-08T10:35:54","date_gmt":"2019-02-08T10:35:54","guid":{"rendered":"https:\/\/blog.hostinger.io\/support\/2019\/02\/08\/1583224-how-to-fix-error-establishing-a-database-connection-at-hostinger\/"},"modified":"2026-03-16T12:12:18","modified_gmt":"2026-03-16T12:12:18","slug":"1583224-how-to-fix-error-establishing-a-database-connection-at-hostinger","status":"publish","type":"post","link":"https:\/\/www.hostinger.com\/support\/1583224-how-to-fix-error-establishing-a-database-connection-at-hostinger\/","title":{"rendered":"How to Fix \u201cError Establishing a Database Connection\u201d at Hostinger"},"content":{"rendered":"<p class=\"no-margin\">The error establishing a database connection (&ldquo;Error establishing a database connection&rdquo;, &ldquo;Access denied for user&rdquo;, or similar) can be pinpointed to a few things:<\/p><ol>\n<li>\n<p class=\"no-margin\">Check the current <b><a href=\"\/support\/1583552-how-can-i-locate-my-mysql-database-details\" target=\"_blank\" class=\"intercom-content-link\">database parameters<\/a><\/b><\/p>\n<\/li>\n<li>\n<p class=\"no-margin\">Find the <b><a href=\"\/support\/3313359-where-to-find-configuration-file-of-my-website\" target=\"_blank\" class=\"intercom-content-link\">website&rsquo;s configuration file<\/a><\/b><\/p>\n<\/li>\n<li>\n<p class=\"no-margin\"><b>Match the parameters<\/b> of your actual database with the configuration file<\/p>\n<\/li>\n<\/ol><p class=\"no-margin\">If you use <b>WordPress<\/b>, you may refer to a dedicated tutorial here: <b><a href=\"https:\/\/www.hostinger.com\/tutorials\/wordpress-error-establishing-database-connection\" target=\"_blank\" class=\"intercom-content-link\">Error Establishing A Database Connection on WordPress<\/a><\/b> &#128161; <\/p><p class=\"no-margin\">\n<\/p><p class=\"no-margin\">For other CMSs, take a look at this video tutorial or follow the steps below:<\/p><p class=\"no-margin\">\n<\/p><div class=\"intercom-h2b-video\">\n<iframe loading=\"lazy\" title=\"How to Fix Error Establishing a Database Connection\" width=\"500\" height=\"281\" src=\"https:\/\/www.youtube.com\/embed\/WsdND0nun6s?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n<\/div><hr><p class=\"no-margin\">\n<\/p><h2 id=\"step-1---checking-the-current-database-parameters\">Step 1 &mdash; Check the Current Database Parameters<\/h2><p class=\"no-margin\">In the <b><a href=\"https:\/\/hpanel.hostinger.com\/websites\" target=\"_blank\" class=\"intercom-content-link\" rel=\"noopener\">Websites<\/a> <\/b>section, click on<b> Manage <\/b>next to the site in question, and search for <b>Databases<\/b> <b>Management<\/b>: <\/p><p class=\"no-margin\">\n<\/p><div class=\"intercom-container intercom-align-center\"><img decoding=\"async\" src=\"\/support\/wp-content\/uploads\/sites\/55\/2019\/02\/ca69555b-89fa-4e16-8a3b-d3904cddc0fd.jpg\"><\/div><p class=\"no-margin\">\n<\/p><p class=\"no-margin\">Check the <b>List of Current MySQL Databases And Users<\/b>.<b> <\/b>You will find there your database credentials:<\/p><p class=\"no-margin\">\n<\/p><div class=\"intercom-container intercom-align-center\"><img decoding=\"async\" src=\"\/support\/wp-content\/uploads\/sites\/55\/2019\/02\/aa6d29ff-7358-49d5-9328-9f991dc14480.jpg\"><\/div><p class=\"no-margin\">\n<\/p><p class=\"no-margin\">Copy them to a TXT file or leave the databases tab open on your browser, as you will need these details in the next step.<\/p><p class=\"no-margin\">\n<\/p><p class=\"no-margin\">If you&rsquo;re not sure about the <b>password of your database<\/b>, you can <b>change it<\/b> by following this guide:<b> <a href=\"\/support\/1583522-how-to-change-database-password\" target=\"_blank\" class=\"intercom-content-link\">How to Change the Database Password<\/a><\/b>.<\/p><p class=\"no-margin\">\n<\/p><h2 id=\"step-2---open-configuration-file\">Step 2 &mdash; Open the Configuration File<\/h2><p class=\"no-margin\">In the <b><a href=\"https:\/\/hpanel.hostinger.com\/websites\" target=\"_blank\" class=\"intercom-content-link\" rel=\"noopener\">Websites<\/a> <\/b>section, click on<b> Manage <\/b>next to the site in question, and search for <b>File Manager<\/b>:<\/p><p class=\"no-margin\">\n<\/p><div class=\"intercom-container intercom-align-center\"><img decoding=\"async\" src=\"\/support\/wp-content\/uploads\/sites\/55\/2019\/02\/25076579-fb12-476e-83bc-3df942dcaece.jpg\"><\/div><p class=\"no-margin\">\n<\/p><p class=\"no-margin\">Choose to access the files of the particular website, open the<b> public_html <\/b>folder, and look for the website&rsquo;s <b><a href=\"\/support\/3313359-where-to-find-configuration-file-of-my-website\" target=\"_blank\" class=\"intercom-content-link\">configuration file<\/a><\/b> there.<\/p><p class=\"no-margin\">\n<\/p><h2 id=\"step-3---matching-the-credentials\">Step 3 &mdash; Match the Credentials<\/h2><p class=\"no-margin\">In the configuration file, find the fields that connect your website to the database and enter the correct data. Expand the corresponding section for the instructions related to your CMS:<\/p><p class=\"no-margin\">\n<details>\n<summary>\n<h3>OpenCart<\/h3>\n<\/summary>\n<div class=\"collapsible-section-content\">\n<p class=\"no-margin\">Open the file <b>config.php <\/b>inside the <b>public_html<\/b> folder of your domain. You need to specify the values corresponding to your database &#8203;&#8203;as follows: <\/p>\n<ul>\n<li>\n<p class=\"no-margin\">DB_USERNAME &mdash; the database username<\/p>\n<\/li>\n<li>\n<p class=\"no-margin\">DB_PASSWORD &mdash; the database password<\/p>\n<\/li>\n<li>\n<p class=\"no-margin\">DB_DATABASE &mdash; the database name<\/p>\n<\/li>\n<\/ul>\n<p class=\"no-margin\">The result should look similar to this: <\/p>\n<p class=\"no-margin\">\n<\/p><div class=\"intercom-container intercom-align-center\"><img decoding=\"async\" src=\"\/support\/wp-content\/uploads\/sites\/55\/2019\/02\/517eee4e-10d0-4ca8-897a-0f340cc4f675.jpg\"><\/div>\n<p class=\"no-margin\">\n<\/p><p class=\"no-margin\">OpenCart has another <b>config.php <\/b>configuration file that can be found in the <b>\/public_html\/admin\/<\/b> directory. Open it and enter the same information as in <b>\/public_html\/config.php<\/b>.<\/p>\n<p class=\"no-margin\">\n<\/p><\/div>\n<\/details>\n<details>\n<summary>\n<h3>Joomla<\/h3>\n<\/summary>\n<div class=\"collapsible-section-content\">\n<p class=\"no-margin\">Open the <b>configuration.php <\/b>file inside the <b>public_html<\/b> folder of your domain. Here, you need to specify the values corresponding to your database &#8203;&#8203;as follows: <\/p>\n<ul>\n<li>\n<p class=\"no-margin\">public $ user = the database username<\/p>\n<\/li>\n<li>\n<p class=\"no-margin\">public $ password = the database password<\/p>\n<\/li>\n<li>\n<p class=\"no-margin\">public $ db = the database name<\/p>\n<\/li>\n<\/ul>\n<p class=\"no-margin\">The result should look similar to this: <\/p>\n<p class=\"no-margin\">\n<\/p><div class=\"intercom-container intercom-align-center\"><img decoding=\"async\" src=\"\/support\/wp-content\/uploads\/sites\/55\/2019\/02\/e5491f44-6af5-4c98-ba4e-e1637502a3d0.jpg\"><\/div>\n<p class=\"no-margin\">\n<\/p><p class=\"no-margin\">Make sure not to add any additional spaces or delete any existing symbols to avoid website errors. <\/p>\n<p class=\"no-margin\">\n<\/p><\/div>\n<\/details>\n<details>\n<summary>\n<h3>PrestaShop<\/h3>\n<\/summary>\n<div class=\"collapsible-section-content\">\n<p class=\"no-margin\">Open the <b>parameters.php <\/b>file inside the <b>public_html\/app\/config <\/b>folder of your domain. Here, you need to specify the values corresponding to your database &#8203;&#8203;as follows: <\/p>\n<ul>\n<li>\n<p class=\"no-margin\">&lsquo;database_name&rsquo; =&gt; the database name<\/p>\n<\/li>\n<li>\n<p class=\"no-margin\">&lsquo;database_user&rsquo; =&gt; the database username<\/p>\n<\/li>\n<li>\n<p class=\"no-margin\">&lsquo;database_password&rsquo; =&gt; the database password<\/p>\n<\/li>\n<\/ul>\n<p class=\"no-margin\">The result should look similar to this: <\/p>\n<p class=\"no-margin\">\n<\/p><div class=\"intercom-container intercom-align-center\"><img decoding=\"async\" src=\"\/support\/wp-content\/uploads\/sites\/55\/2019\/02\/bb90f845-b59f-4b11-8a8b-36e2b1093edd.jpg\"><\/div>\n<p class=\"no-margin\">\n<\/p><\/div>\n<\/details>\n<details>\n<summary>\n<h3>Moodle<\/h3>\n<\/summary>\n<div class=\"collapsible-section-content\">\n<p class=\"no-margin\">Open the <b>config.php <\/b>file inside the <b>public_html<\/b> folder of your domain. Here, you need to specify the values corresponding to your database &#8203;&#8203;as follows: <\/p>\n<ul>\n<li>\n<p class=\"no-margin\">$CFG-&gt;dbname = the database name<\/p>\n<\/li>\n<li>\n<p class=\"no-margin\">$CFG-&gt;dbuser = the database username<\/p>\n<\/li>\n<li>\n<p class=\"no-margin\">$CFG-&gt;dbpass = the database password<\/p>\n<\/li>\n<\/ul>\n<p class=\"no-margin\">The result should look similar to this: <\/p>\n<p class=\"no-margin\">\n<\/p><div class=\"intercom-container\"><img decoding=\"async\" src=\"\/support\/wp-content\/uploads\/sites\/55\/2019\/02\/346f7ff0-e330-4ed2-a522-8e37107c1509.jpg\"><\/div>\n<\/div>\n<\/details>\n<\/p><p class=\"no-margin\">\n<\/p><p class=\"no-margin\">After the new values &#8203;&#8203;are set, save the changes and open your website using an <b>incognito browsing mode<\/b>.<\/p><p class=\"no-margin\">\n<\/p><p class=\"no-margin\"><b>NOTES<\/b><\/p><ul>\n<li>\n<p class=\"no-margin\">Some CMS have an additional <b>variable for table prefixes<\/b>. To ensure the website&rsquo;s configuration file value matches the actual prefix, <b><a href=\"\/support\/1583545-how-to-access-phpmyadmin-in-hpanel\" target=\"_blank\" class=\"intercom-content-link\">open the database via phpMyAdmin<\/a><\/b> and check the names of the tables. The prefix is a short series of letters followed by an underscore, for example, <b>xhfv_ &#128161; <\/b><\/p>\n<\/li>\n<li>\n<p class=\"no-margin\">While the default hostname for MySQL is <b>localhost<\/b>, some CMS use <b>mysql<\/b> or <b>127.0.0.1<\/b>.; we recommend you leave the default value used in your CMS <\/p>\n<\/li>\n<\/ul><p class=\"no-margin\">\n<\/p><h2 id=\"if-the-error-persists\">If the Error Persists<\/h2><p class=\"no-margin\">If the error persists after double-checking your database credentials and <b><a href=\"\/support\/1583501-how-to-clear-cache\" target=\"_blank\" class=\"intercom-content-link\">clearing the cache<\/a><\/b>, it usually means that the<b> password <\/b>you&rsquo;ve set to your database is different from the one entered in the configuration file. <\/p><p class=\"no-margin\">\n<\/p><p class=\"no-margin\">To fix it, open your configuration file and copy the current password, making sure <b>not to copy any adjacent symbols<\/b>. Next, <b><a href=\"\/support\/1583522-how-can-i-recover-mysql-password\" target=\"_blank\" class=\"intercom-content-link\">set the database password<\/a><\/b> to the one you have copied from the config file by pasting it as the new value.<\/p><p class=\"no-margin\">\n<\/p><p class=\"no-margin\">That&rsquo;s it! Your website should be working without database errors now &#128522;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Fixing a database configuration error on Joomla, OpenCart, and other CMS<\/p>\n","protected":false},"author":581,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"include_on_kodee":true,"footnotes":""},"categories":[180],"tags":[],"class_list":["post-1584","post","type-post","status-publish","format-standard","hentry","category-website-troubleshooting"],"hreflangs":[{"locale":"en-US","link":"https:\/\/www.hostinger.com\/support\/1583224-how-to-fix-error-establishing-a-database-connection-at-hostinger\/","default":1},{"locale":"es-ES","link":"https:\/\/www.hostinger.com\/es\/support\/1583224-como-solucionar-el-error-error-establishing-a-database-connection-en-hostinger\/","default":0},{"locale":"fr-FR","link":"https:\/\/www.hostinger.com\/fr\/support\/1583224-comment-corriger-error-establishing-a-database-connection-hostinger\/","default":0},{"locale":"id-ID","link":"https:\/\/www.hostinger.com\/id\/support\/1583224-cara-mengatasi-error-establishing-a-database-connection-hostinger\/","default":0},{"locale":"pt-PT","link":"https:\/\/www.hostinger.com\/br\/support\/1583224-como-corrigir-o-erro-ao-estabelecer-uma-conexao-com-o-banco-de-dados-hostinger\/","default":0},{"locale":"uk-UA","link":"https:\/\/www.hostinger.com\/ua\/support\/1583224-----\/","default":0}],"include_on_kodee":true,"_links":{"self":[{"href":"https:\/\/www.hostinger.com\/support\/wp-json\/wp\/v2\/posts\/1584","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hostinger.com\/support\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hostinger.com\/support\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/support\/wp-json\/wp\/v2\/users\/581"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/support\/wp-json\/wp\/v2\/comments?post=1584"}],"version-history":[{"count":2,"href":"https:\/\/www.hostinger.com\/support\/wp-json\/wp\/v2\/posts\/1584\/revisions"}],"predecessor-version":[{"id":6290,"href":"https:\/\/www.hostinger.com\/support\/wp-json\/wp\/v2\/posts\/1584\/revisions\/6290"}],"wp:attachment":[{"href":"https:\/\/www.hostinger.com\/support\/wp-json\/wp\/v2\/media?parent=1584"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hostinger.com\/support\/wp-json\/wp\/v2\/categories?post=1584"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hostinger.com\/support\/wp-json\/wp\/v2\/tags?post=1584"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}