How to Change Database Name in Magento 2
The latest Magento 2 comes with not only improved security, performance, and ease of use but also some changes in the file structure.
The configuration file differs from the one in Magento 1. For example:
In the previous version of Magento, the database configuration file was located in app/etc/local.xml, whereas, in Magento 2, the file address is app/etc/env.php
The database configuration file holds information like server hostname, username, password, database name, view of backups, database edits, and every alteration you need to work with MySQL.
This blog post will guide you on how to change database name in Magento 2.
Use the below solution when you have FTP access, but you don’t know database credentials while working with a live site.
Method to Change Database Name in Magento 2
- In your Magento 2 folder structure, open env.php file from app/code/
- Change the database name by modifying name of ‘dbname‘.
123456789101112131415'db' => ['table_prefix' => '','connection' => ['default' => ['host' => 'localhost','dbname' => 'magento_db','username' => 'root','password' => 'admin123','model' => 'mysql4','engine' => 'innodb','initStatements' => 'SET NAMES utf8;','active' => '1']]]
Here, database name is magento_db. Now change the name of database to your selected name in the dbname.
That’s it
If you have any doubt regarding the above solution, do mention them in the Comments section below.
I would be happy to help.
Feel free to share the method with Magento Community via social media.
Thank You.
Jignesh Parmar
An expert in his field, Jignesh is the team leader at Meetanshi and a certified Magento developer. His passion for Magento has inspired others in the team too. Apart from work, he is a cricket lover.
Prev
How to Fetch Bearer Token in Magento 2
How to Enable or Disable Maintenance Mode in Magento 2
Next