How to change magento database configuration file

The name of database configuration file of Magento is local.xml, open your file manager client and navigate to: <Magento installation folder>/app/etc/local.xml.  

  • When installing a fresh Magento site
  • When changing database for Magento site
  • When moving your Magento website to another server

If you cannot find your local.xml file in app/etc/local.xml, download original local.xml file here on Gist:

  • Error while installing Magento: database connection error

If the database configuration is not set properly, we can see error messages such as:

  • Error while accessing Magento site with wrong database configuration (if this is not the cause of this error message, read this tutorial to learn how to fix)

Now you can see the following important lines:
database connection error magento

Path to database configuration file of Magento

In this tutorial, we will learn how to access Magento database configuration file to edit database information.
When working with Magento, sometimes you will need to edit and change content in the Magento database configuration file so that your Magento website will work with the new Database you assign to. For example:

Edit database configuration

Edit file, go to line 42 and you will see the following content

Now replace with your database information, for example

  • Database username<username><![CDATA[root]]></username>
  • Database password<password><![CDATA[#123456]]></password>
  • Database name<dbname><![CDATA[database_name]]></dbname>

local xml file location

  • <username><![CDATA[magentoexplorer]]></username>
  • <password><![CDATA[sx@esax]]></password>
  • <dbname><![CDATA[magentodemo]]></dbname>

After changing content, save your file and flush cache if your Magento site is not changed.
database error magento

How to change magento database configuration file
4.9 (98%) 10 votes