How To Change Database Name In Magento 2

In this post, I will guide you on How To Change Database Name In Magento 2. The env file contains information about the database like dbname, username, and password, and you can change them to work with the MySQL server.

This should be done when you move host or change a new database. Here’s how you can get the job done quickly through our guide below:

Steps To Change Database Name In Magento 2

1.  First, you need to connect to your server via SSH as the root user by command:

ssh root@<your-ip-address> -p <your-port-number>

2. Go to Magento 2 root folder.

3. Open env.php file with the below given path.

app/etc/env.php
Open env.php file

4. Navigate to the db and check the “dbname” property. You can see it in env.php file like this:

'db' => [
        'table_prefix' => '',
        'connection' => [
            'default' => [
                'host' => 'localhost',
                'dbname' => 'magento2',
                'username' => 'root',
                'password' => '',
                'model' => 'mysql4',
                'engine' => 'innodb',
                'initStatements' => 'SET NAMES utf8;',
                'active' => '1',
                'driver_options' => [
                    1014 => false
                ]
            ]
        ]
    ],

5. Here, the database name is “magento2”. Now you can change the name of the database to the name you want to set.

For example the database name you want to change is “magento242”, it will look like below:

'dbname' => 'magento242',

So you have done it successfully!

This is the end of the post.

Follow us for the more helpful posts!

We hope this is a useful post for you on How To Change MySQL Password Policy Level.

Thank you for reading!

4.7 3 votes
Article Rating

Aaron LX

Aaron is a passionate writer, crazy about shopping, eCommerce and trends. Besides his outstanding research skills and a positive mind, Aaron eagerly shares his experience with the readers.

Leave a Reply or put your Question here

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x