Magento Tutorials

How to Create the Magento Database Schema

What is Database Schema?

Database Schema is the structure of data in a database. It defines how data is organized and how data relationships are governed, including all constraints applied to the data. A module can contain fragments of the database schema if that module has data that needs to be stored in the database.

How to Create the Magento Database Schema

Step 1: Log in to Magento server

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:

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:

sudo -u <Magento file system owner>  <command>

Step 2: Run Magento commands

To run Magento commands from any directory, add <your Magento install dir>/bin to your system PATH.

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

bash shell example for CentOS:

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

You can also run the commands in the following ways:

  • cd <your Magento install dir>/bin and run them as ./magento <command name>
  • php <your Magento install dir>/bin/magento <command name>

Step 3: Create or update the Magento deployment configuration

Before you run the command to configure the database, you must create or update the deployment configuration. Magento’s deployment configuration provides the information Magento needs to initialize and bootstrap.

You can use this command if:

  • You previously installed the Magento software and you want to modify the deployment configuration
  • If you want to create only the deployment configuration and continue the Magento installation some other way
  • To update the deployment configuration without affecting anything else

Command options:

magento setup:config:set [--<parameter>=<value>, ...]

Step 4: Configure the database and add data

Command usage:

magento setup:db-schema:upgrade
magento setup:db-data:upgrade

To see the status of the database, enter

magento setup:db:status

Further Reading:

Understanding ​Magento Database Structure
How to Edit Magento Database Configuration File
How to use Magento Database Repair Tool
Magento 2 Database Configuration File (local.xml)

Is it helpful?

Avatar

Marketing Executive/ Product Designer at SimiCart

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments