How to change magento database configuration file


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:

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

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

  • Error while installing Magento: database connection error

database connection error magento

  • 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)

database error magento

In this tutorial, we will learn how to access Magento database configuration file to edit database information.

Path to database configuration file of Magento

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.  

local xml file location

Edit database configuration

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

Now you can see the following important lines:

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

Now replace with your database information, for example

  • <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.

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

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


About Author

Daniel is a Magento developer with 5 years of experience with customizing Magento extensions, Magento templates. He's main author at Magento explorer

1 Comment

Leave A Reply