I posted a Find and Replace entry before, but here’s a more step-by-step walkthrough for those who have no knowledge of SQL. I posted this as a comment on Owen’s blog, but some other people may be interested, so here’s a basic overview of how to update URLs in your blog (useful if you change domains):
BACK UP YOUR DATABASE FIRST!
You may want to run this on a small test case first as well, to make sure you understand the concept. For instance, you could pick your two latest posts and append the text QZQZQZ at the end. You could then run this example to make sure that the query replaces QZQZQZ with a new string, say SBSBSB.
In this example, several sites that were hosted at ikamashou.net had to move to dasaku.net (but their subdomains remained the same). To make sure that all the absolute URLs continue to work, we do a little find and replace magic on the database in phpMyAdmin.
Go to your your cpanel, log in and select the icon for phpMyAdmin
Select your WP database from the dropdown menu, then click on the wp_posts table from the list on the left sidebar (meaning your table name is wp_posts)
Click on the search tab and search for post_content LIKE %ikimashou.net% where the percentage marks indicate a wildcard, and note that the field name is post_content
The reason to search first is to make sure that you are searching on the correct term (note that you will not use the % in the actual query)
The syntax of the SQL query (without brackets) to replace a string is: UPDATE [table_name] SET [field_name] = REPLACE([field_name],'[string_to_find]','[string_to_replace]');
To replace ikamashou.net with dasaku.net in all posts where ikamashou.net appears, your SQL code will be: UPDATE wp_posts SET post_content = REPLACE (post_content, 'ikimashou.net','dasaku.net');
To replace ikamashou.net with dasaku.net in all author URLs in comments, your SQL code will be: UPDATE wp_comments SET comment_author_url = REPLACE (comment_author_url, 'ikimashou.net','dasaku.net');
Don’t forget the semicolon at the end (;)
Click on the SQL tab at the top and type/paste the SQL code in before clicking GO to actually run the query and fix all the URLs
You can repeat this process for as many strings as you would like, but take note of which table you are updating (in the first example it is wp_posts but in the second example it is wp_comments) and which field name you are updating (the field name is typed in twice, and in the first example it is post_content but in the second example it is comment_author_url)
I’m not an SQL guru or anything, and I will refine the tutorial if I have made any mistakes. Keep in mind that find and replace in a database can be a powerful tool, but one that can go horribly awry. Only replace unique values (such as gibberish characters, or URLs) or you may inadvertently replace some values that you didn’t mean to replace.
Updating Obsolete URLs in 10 Easy Steps
I posted a Find and Replace entry before, but here’s a more step-by-step walkthrough for those who have no knowledge of SQL. I posted this as a comment on Owen’s blog, but some other people may be interested, so here’s a basic overview of how to update URLs in your blog (useful if you change domains):
BACK UP YOUR DATABASE FIRST!
You may want to run this on a small test case first as well, to make sure you understand the concept. For instance, you could pick your two latest posts and append the text QZQZQZ at the end. You could then run this example to make sure that the query replaces QZQZQZ with a new string, say SBSBSB.
In this example, several sites that were hosted at ikamashou.net had to move to dasaku.net (but their subdomains remained the same). To make sure that all the absolute URLs continue to work, we do a little find and replace magic on the database in phpMyAdmin.
%ikimashou.net%where the percentage marks indicate a wildcard, and note that the field name is post_content%in the actual query)UPDATE [table_name] SET [field_name] = REPLACE([field_name],'[string_to_find]','[string_to_replace]');UPDATE wp_posts SET post_content = REPLACE (post_content, 'ikimashou.net','dasaku.net');UPDATE wp_comments SET comment_author_url = REPLACE (comment_author_url, 'ikimashou.net','dasaku.net');I’m not an SQL guru or anything, and I will refine the tutorial if I have made any mistakes. Keep in mind that find and replace in a database can be a powerful tool, but one that can go horribly awry. Only replace unique values (such as gibberish characters, or URLs) or you may inadvertently replace some values that you didn’t mean to replace.
Related posts: