MySQL Search / Replace - Switching root domain on Wordpress Multisite - mysql

I have a Wordpress Multisite installation, and the root domain is set to root-domain.com. I would like to switch it with one of the sites of the network (site-in-network.com), and make it a root domain.
This way site-in-network.com would become the root domain, and root-domain.com would become one of the sites in the network (100+ sites).
I've done search and replace on a database before, and it worked, but I was dropping a domain all together, so I just replaced domain-a.com with domain-b.com. This time it is different, I want to keep both of them, and just switch the positions in the database.
I guess I would need to run a MySQL query. As far as I know, the root domain was set to something like "www.root-domain.com", and all other sites in the network were like "site-in-network.com" (without the .www part)
The database is about 0.5GB, so it would be good to get it right the first time.
Thank you in advance for any info.

It can be done with a search and replace, but mind you that wordpress is also storing site information in a serialized form in the tables. That means that a default search and replace will break a lot of stuff, so be careful with that.
There is however a script that takes this into account: http://interconnectit.com/products/search-and-replace-for-wordpress-databases/
Download it and put it in your root folder. (And afterwards, delete it!!)
Using this script you could change root-domain.com to root-domain.tmp.com and then site-in-network.com to root-domain.com. After that you could rename root-domain.tmp.com to site-in-network.com. Basicly what Plamen Nikolov suggested to do in the first place.

Here is a little bit of a craftily solution:
You can still workaround the situation with the find and replace technique using fake domain name:
Replace site-in-network.com with some-fake-unique-name.com
Replace root-domain.com with site-in-network.com
Finally some-fake-unique-name.com with root-domain.com.
There is also solution without changing the database, by definining HOME and SITE URL like here: Changing the Site URL

Related

how to delete all urls in database

I previously used an old CMS.
I moved to wordpress and I've done a lot of work, but I still have in my very old articles 1000+ internal links pointing to old urls.
I've set up redirects, but I would like to actually replace / delete the very old internal linking in the wordpress database.
I have 3 types of old linking :
/articles.php?lng=fr&pg=425 .......... so like /articles.php?stuff
/news.php?lng=fr&pg=1827 .......... so like /news.php?stuff
/2456-actualite .......... so like /id-actualite
I believe that "Search and replace" and "Better search and replace", both Wordpress plugins are only dealing with exact urls, while the ids are dynamic.
How would you delete those all links in the database, but keeping the hypertext of those links?
Thanks !
Have you tried using WP Cli?
It's a very powerful tool for this kind of problems by running some commands on your server.
Example:
# Search and replace but skip one column
$ wp search-replace 'http://example.dev' 'http://example.com' --skip-columns=guid
Have a look more on their search-replace command.
It is probably impossible to change each URL by hand.. much better way is to use something like this "https://wordpress.org/plugins/search-and-replace/" to replace all URLs you need in the database. - This does not only deal with urls but with any other text too.

MySQL Replace Breaks Wordpress Template

I am making a copy of a WordPress website on another server. Everything is OK in copying the database.
However, I need to replace the old domain name "old.com" with "new.com" in some MySQL tables. I am using the following query:
UPDATE wp_options SET option_value = REPLACE(option_value, 'https://old.com/', 'http://new.com/')
This works for a lot of things (like the site URL), however, it breaks all my CSS modifications to the template and all my options, it's sort of restored into default settings directly after I run the previous command.
What could be the reasons?
When moving a Wordpress table the Database Search and Replace Script by interconnect/it does the job very well.
https://interconnectit.com/products/search-and-replace-for-wordpress-databases/
The software is designed for exactly the purpose of replacing olddomain.com with newdomain.com.
All you do is extract Search Replace DB to it's own directory off the root of the Wordpress installation. You then run
newdomain.com/Search-Replace-DB-master
This will automatically find your Wordpress database and will provide search and replace field. It allows a dry run where you can check the results before doing the live run.
Hope this is useful. I have used this many times when changing the domain for a Wordpress installation and it works every time.
Never manually replace URL use https://wordpress.org/plugins/velvet-blues-update-urls/ plugin to safely search & replace old URL with new one.

Moodle - where are URLs/links stored in database?

I'm exporting an old release 1.9.2 and importing to 3.0.2.
Each module has dozens of videos that I play via an URL/link, which points to my own .PHP program on the site (and that wraps a Camtasia video).
I found that in 3.0.2, the link opens on a separate page, unless I edit each link by going to "Appearance", then "Display" and setting it to "Embed".
So I would like to write a mySQL update script to automatically set this flag for all such links (I will add a where clause to my script name).
I checked database in PHP/MyAdmin, and didn't see any likely table names.
You should attempt to use the admin tools to update everything, go to your moodle installation's main URL.
Then go to the site administration. After /admin in the url, add /tool/replace and go there.
You can there enter what you want to find in the db, and replace it with another value. Just be carefull with this tool and make a backup before you begin.

Replace MySql database root image links with subdomain folders?

Im trying to figure out a way to update some of my images in my database which are pointing to the wrong place. It was easy to do with the images which were in the wrong subfolder as I could just use a simple plugin to search for http://url.com/sub1/folder/ and change to http://url.com/sub2/folder/
But these are in root, so http://url.com/image.jpg and need to be http://url.com/sub2/folder/image.jpg
Can I use phpMyadmin to search for http://url.com/*.jpg and replace with http://url.com/sub2/folder/*jpg or another method?
Recent versions of phpMyAdmin have a find and replace feature which sounds like it might be what you're after.
This can be located by going to the table you wish to search and clicking the Search tab, then Find and Replace. Put your old URL in the "Find" field and new URL in the "Replace with" field, and click Go to preview the changes. It never hurts to have a backup of your data when making changes.

Move images from service and update paths in forum

I run a popular forum where one of the members who has made a lot of awesome contributions recently contacted us. He has posted several hundred images from his webshots gallery, but the service is changing as are all the images. I need to change all the image src paths in all of his posts in our mysql database.
He was given the opportunity to download all the images which he has given to me. Because I will be having to do a lot of these changes in production I need to make sure that I don't screw this up.
The image src in his posts look similar to this, where 0103935217 I believe is his user ID.
http://inlinethumb25.webshots.com/47576/2156388770103935217S500x500Q85.jpg
The images downloaded from the service look like this. Notice the S500x500Q85 has been replaced with a random string.
2156388770103935217Reacil_fs.jpg
So I have two tasks:
I need to rename the all the files I've put on my server removing the random characters and the _fs designation.
I need to change the file paths in all of his posts removing domain and container and replacing it with mine. In addition I need to remove the S500x500Q85 designation.
For 1. I have a regex but I'm unsure how to do the replacement 0103935217\w+?_fs
For 2. I know my query needs to be something along the lines of the below. I'm a little unsure how to do this though, is it with a regex?
UPDATE posts SET post_body = replace(post_body, '','') WHERE user_id = 1234