CMS
Now Reading
How To Change The Domain For Magento In MySQL From The Command Line
0

How To Change The Domain For Magento In MySQL From The Command Line

by Adrian RandallJanuary 24, 2016

We deploy Magento sites all around the place and often we did not setup the hosting environment, are limited to what we can do on the hosting environment or just plain forgot to change the domain name locally in the database before we backed up the database to deploy.

As you all know, or have stumbled across this post because you’re having an issue, Magento sets the domain name in the database for the base_url and the secure_base_url. If these are set to something different than the domain you are deploying the site to, it will redirect off to that domain. Simple.

So we are assuming you have restored a Magento database to a server and just need to change the base URLs to match your new domains so it doesn’t keep redirecting. If you haven’t restored your database and the database is big then here is a link to restore the MySQL Database backup

  1. Login to MySQL from the command line:

   mysql -u root -p

You will be prompted for your password

  1. Set the database you want to us:

use myMagentoDatabase;

  1. Find the rows which have the domain names set:

select * from core_config_data where path like ‘%base%url%’;

You should see a result something like this with dev.magento.com.au being my test domain which I want to replace:

  1. Now we need to update the rows which have the domain set. I normally update them by the ‘path’ value as I know it’s unique but some people like to use the config_id…it’s up to you:

update core_config_data set value = ‘http://dev.magento.com.au/’ where path = ‘web/unsecure/base_url’;
update core_config_data set value = ‘http://dev.magento.com.au/’ where path = ‘web/secure/base_url’ ; 

  1. From here just exit your MySQL command prompt:

exit;

All done!

About The Author
Adrian Randall
I'm a digital marketing specialist, love working on digital business and coding on just about anything. I'm the founder of Arcadian Digital and this site shares some of our knowledge and practices.

Leave a Response