Magento 2.1.18 is the final 2.1.x release. After June 2019, Magento 2.1.x will no longer receive security patches, quality fixes, or documentation updates.
To maintain your site's performance, security, and PCI compliance, upgrade to the latest version of Magento.
Magento Commerce only

Automatically configure master databases

Overview of master databases

This topic discusses how to get started with the split database solution by:

  1. Installing Magento Commerce with a single master database (named magento)
  2. Creating two additional master databases for checkout and OMS (named magento_quote and magento_sales)
  3. Configuring Magento Commerce to use the checkout and sales databases

This guide assumes all three databases are on the same host as the Magento application and that they’re named magento, magento_quote, and magento_sales. However, the choice of where to locate the databases and what they’re named is up to you. We hope our examples make the instructions easier to follow.

Install the Magento Commerce software

You can enable split databases at any time after you install the Magento Commerce software; in other words, you can add split databases to a Magento Commerce system that already has checkout and order data. Use the instructions in the Magento Commerce README or the installation guide to install the Magento Commerce software using a single master database.

Set up additional master databases

Create checkout and OMS master databases as follows:

  1. Log in to your database server as any user.
  2. Enter the following command to get to a MySQL command prompt:

    1
    
    mysql -u root -p
    
  3. Enter the MySQL root user’s password when prompted.
  4. Enter the following commands in the order shown to create database instances named magento_quote and magento_sales with the same usernames and passwords:

    1
    2
    3
    4
    5
    
    create database magento_quote;
    GRANT ALL ON magento_quote.* TO magento_quote@localhost IDENTIFIED BY 'magento_quote';
    
    create database magento_sales;
    GRANT ALL ON magento_sales.* TO magento_sales@localhost IDENTIFIED BY 'magento_sales';
    
  5. Enter exit to quit the command prompt.

  6. Verify the databases, one at a time:

    Checkout database:

    1
    2
    
    mysql -u magento_quote -p
    exit
    

    Order management database:

    1
    2
    
    mysql -u magento_sales -p
    exit
    

    If the MySQL monitor displays, you created the database properly. If an error displays, repeat the preceding commands.

Configure Magento Commerce to use the master databases

After setting up a total of three master databases, use the Magento command line to configure Magento to use them. (The command sets up database connections and distributes tables among the master databases.)

First steps

  1. Log in to the Magento server as, or switch to, a user who has permissions to write to the Magento file system. One way to do this is to switch to the Magento file system owner.

If you use the bash shell, you can also use the following syntax to switch to the Magento file system owner and enter the command at the same time:

1
su <Magento file system owner> -s /bin/bash -c <command>

If the Magento file system owner does not allow logins you can do the following:

1
sudo -u <Magento file system owner>  <command>
  1. To run Magento commands from any directory, add <magento_root>/bin to your system PATH.

Because shells have differing syntax, consult a reference like unix.stackexchange.com.

bash shell example for CentOS:

1
export PATH=$PATH:/var/www/html/magento2/bin

You can also run the commands in the following ways:

  • cd <magento_root>/bin and run them as ./magento <command name>
  • <magento_root>/bin/magento <command name>
  • <magento_root> is a subdirectory of your web server’s docroot. Need help locating the docroot?

Configure the checkout database

Command syntax:

1
magento setup:db-schema:split-quote --host="<checkout db host or ip>" --dbname="<name>" --username="<checkout db username>" --password="<password>"

For example,

1
magento setup:db-schema:split-quote --host="localhost" --dbname="magento_quote" --username="magento_quote" --password="magento_quote"

The following message displays to confirm a successful setup:

1
Migration has been finished successfully!

Configure the OMS database

Command syntax:

1
magento setup:db-schema:split-sales --host="<checkout db host or ip>" --dbname="<name>" --username="<checkout db username>" --password="<password>"

For example,

1
magento setup:db-schema:split-sales --host="localhost" --dbname="magento_sales" --username="magento_sales" --password="magento_sales"

The following message displays to confirm a successful setup:

1
Migration has been finished successfully!

Next step

Verify split databases

Updated