0

I'm running custom script on my Linux Server.

I don't want that script to affect my current database. Username/Password/Host will be same.

Only DB name is changed. How can I do that without changing in env.php?

// MAGENTO START
include(dirname(__DIR__) . '/app/bootstrap.php');

use Magento\Framework\App\Bootstrap;

$bootstrap = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();

$state = $objectManager->get('Magento\Framework\App\State');
$state->setAreaCode('frontend');
$deploymentConfig = $objectManager->create('Magento\Framework\App\DeploymentConfig');
$dbName = $deploymentConfig->get('db/connection/default/dbname'); // Get Current DB Name

On server my website is already running. Don't want to affect that. So need to run script for new DB only.

  • Did you find out how to change the DB name? – Mohammed Joraid Aug 2 '17 at 23:44
0

In Magento, change the name of the database in app/etc/env.php and rename your mysql database this way:

mysqldump old_database > database_content.out
mysql -e "CREATE DATABASE new_database CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"
mysql new_database < database_content.out 
mysql -e "DROP DATABASE old_database;"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.