MySQL Replace Breaks Wordpress Template - mysql

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.

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.

Wordpress - After manually updating mysql table in phpmyadmin for wordpress, the live post reflects the changes, but the post editor does not

Every year we update our posts with new data. For example, the best places to live in 2018.
I am trying to write a python script this year that updates the post_content in mysql so we don't have to do a bunch of copying and pasting into the html post editor.
However, as a test, I manually updated wp_post in phpmyadmin for one article. After updating, the following happens:
The mysql table correctly updates. I can export the table with the changes and they are all in there.
The LIVE article is updated.
However, when I go to edit the article in wordpress's post editor, it's still showing the previous version.
Therefore, if I save the post in post editor, it will revert back to the old version.
I am completely out of ideas. I've been googling for hours and no one seems to
have this problem.
More background on my setup:
Wordpress version 4.9.1
Using dreampress from dreamhost as the host
Here's a link to the working page:
https://www.homesnacks.net/best-places-to-live-in-georgia-122131/
Ended up hooking into the wordpress API:
https://developer.wordpress.org/rest-api/
And these tutorials helped
https://www.cloudways.com/blog/setup-and-use-oauth-authentication-using-wp-rest-api/
https://discussion.dreamhost.com/t/authenticating-to-the-wordpress-api-using-oauth-1-0a-server/65094

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.

MySQL Search / Replace - Switching root domain on Wordpress Multisite

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

Wordpress migration - MySQL guid column

I have a slight problem with a wordpress migration. I've bulk uploaded posts from csv on my local WAMP server as it's faster and then uploaded & imported a SQL dump to the remote server.
In the guid column of the wp_posts table, it contains the url of the post - I presume (might be wrong, please correct if I am) this is the same as the 'permalink' setting when you edit a post - and all of them are http://localhost/post-name/ which is fine for now, I'm happy to work on an SQL query to replace if needed.
I've uploaded the SQL dump and it still shows 'http://localhost/post-name' in the remote server db as expected. However when I search for a post on the frontend, just to make sure it's picking up the posts OK, I was expecting the links to give me a 404 error until I changed the links, but they don't - they point nicely to the http://remoteserver.com/post-name/
Where as it's a nice problem to have as it still works - I was wondering why & do I need to change it? I prefer to not mess with the db if at all possible.
When migrating, you might need to define your wordpress url in wp-config.php, and I recommend find and replacing the database with this tool. It's pretty neat, because it pre-populates your database from your config file. Obviously, you'd replace http://localhost/ with http://www.yoursite.com/
define('WP_HOME','http://example.com');
define('WP_SITEURL','http://example.com');