Separate read and write databases in Magento

Separate read and write databases in Magento

July 13, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Separate read and write databases in Magento

Separate Read and Write Databases in Magento: A Comprehensive Guide

If you’re running an e-commerce store on Magento 1.6.1.0 and looking to improve performance by separating read and write databases, you’ve come to the right place. This technique allows you to distribute load across multiple servers, enhancing scalability and reducing database contention.

Why Separate Read and Write Databases?

Before we dive into the implementation details, let’s quickly discuss why this is a beneficial setup:

  1. Improved Scalability: With two databases, you can handle increased read traffic by distributing it across both servers.
  2. Reduced Database Contention: By separating read and write operations onto different databases, you prevent read-heavy processes from blocking write transactions on the same server.
  3. Better Performance: Each database is optimized for its specific workload—one for quick reads, one for heavy writes.

Configuring Multiple Databases in Magento

The configuration happens primarily in app/etc/local.xml. Here’s a step-by-step guide to setting it up:

1. Add the Write Database Configuration

Open your local.xml file and add the following write database configuration under <resources>:

<write>
    <connection>
        <use_mysql>1</use_mysql>
        <host><![CDATA[localhost]]></host>
        <dbname><![CDATA[magentodb_write]]></dbname>
        <username><![CDATA[magento_user_wr]]></username>
        <password><![CDATA[magento_password_wr]]></password>
    </connection>
</write>

Replace the placeholders with your actual write database credentials.

2. Add the Read Database Configuration

Under <resources>, add the read database configuration similar to this:

<read>
    <connection>
        <use_mysql>1</use_mysql>
        <host><![CDATA[db-read.example.com]]></host>
        <dbname><![CDATA[magentodb_read]]></dbname>
        <username><![CDATA[magento_user_rd]]></username>
        <password><![CDATA[magento_password_rd]]></password>
    </connection>
</read>

Configure the host, dbname, and credentials for your read database here.

3. Configure Magento to Use Multiple Databases

To ensure Magento uses both databases correctly, you need to set some additional parameters:

<resources>
    <mysql54>
        <!--- Write Database Configuration as Above --->
    </mysql54>

    <!-- Read Database Configuration as Above -->

    <default_setup>
        <connection>
            <use_mysql>1</use_mysql>
            <host><![CDATA[localhost]]></host>
            <dbname><![CDATA[magentodb_write]]></dbname>
            <username><![CDATA[magento_user_wr]]></username>
            <password><![CDATA[magento_password_wr]]></password>
        </connection>
    </default_setup>

    <mysql54_magento>
        <!--- Write Database Configuration as Above --->
    </mysql54_magento>

    <!-- Read Database Configuration as Above -->

</resources>

Notice the <mysql54> and <mysql54_magento> sections—these correspond to your actual database configurations.

Remember to backup your local.xml file before making these changes!

Conclusion

Separating read and write databases in Magento is a powerful way to scale your e-commerce platform. By following this guide, you’ve successfully configured two separate databases for optimal performance.

Don’t forget that proper indexing and database optimization are equally important for a smooth operation. If you’d like to dive deeper into Magento performance tuning, I recommend checking out our comprehensive guide at https://laravelcompany.com/magento-performance-tuning.

Happy optimizing!

Magento 1 Database Performance Configuration

Our network