WordPress Multisite – how to change primary domain in mysql cli

While using the wordpress multisite network you sometimes would like to change the domainname of the primary (or main) host/page. Most of the time, this is needed during an upgrade of your site to ssl (https). Usually, this should be made at the early stage of the wordpress site with not much subsites.

Login to your mysql database, change to the wordpress database and check the mysql variables of your wordpress site. Changes need to be made to:

  • wp_options: values of “siteurl” and “home”
  • wp_site
  • wp_sitemeta: value of “siteurl”
  • wp_blogs: value in the “domains” column with the old domain name

Let’s check the values in the database:

SELECT option_name,option_value FROM wp_options WHERE option_name='siteurl' OR option_name='home';
| option_name | option_value                  |
| home        | https://web.olddomain.org    |
| siteurl     | https://web.olddomain.org    |
select * from wp_site;
| id | domain            | path |
|  1 | web.olddomain.org | /    |
select meta_value from wp_sitemeta where meta_key='siteurl';
| meta_value                |
| https://web.olddomain.org/ |
 SELECT domain FROM wp_blogs WHERE blog_id = '1';
 | domain             |
 | web.olddomain.org  |

wp_sitemeta has a different format then the others. Take care of the / at the end of the url!

Now we will change these values to the new site with the mysql cli:

UPDATE wp_options SET option_value='https://web.yournewdomain.org' WHERE option_name='siteurl';
UPDATE wp_options SET option_value='https://web.yournewdomain.org' WHERE option_name='home';
update wp_site set domain='web.yournewdomain.org' where id='1';
update wp_sitemeta set meta_value='https://web.yournewdomain.org/' where meta_key='siteurl';
update wp_blogs set domain='web.yournewdomain.org' where blog_id='1'

You can (should?) now recheck the values with the select statements from above.

That’s it. Just don’t forget to change the multi domain in your wp-config.php file and reload your page.