Knowledge Base

Mass Replacement in the Database

To replace data, log in to phpMyAdmin, select the database (if there are multiple), and create the following query in the SQL section:

UPDATE table SET field = REPLACE(field, 'old_value', 'new_value');

Other examples of syntax are possible:
UPDATE table SET field = REPLACE(field, "old_value", "new_value");

UPDATE 'table' SET 'field' = REPLACE(field, 'old_value', 'new_value');

Explanation:

table – the name of the table where the replacement is made
field – the name of the field where the replacement is made
old_value – the word, text, or data that needs to be replaced
new_value – the word, text, or data to replace with

Examples for WordPress

Replacing old URLs with new ones. This is used when moving from a subdomain to a domain, new URL, or transitioning from http to https:
UPDATE wp_options SET option_value = REPLACE(option_value, 'http://test.mediasova.com', 'https://mediasova.com') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET post_content = REPLACE (post_content, 'http://test.mediasova.com', 'https://mediasova.com');
UPDATE wp_postmeta SET meta_value = REPLACE (meta_value, 'http://test.mediasova.com','https://mediasova.com');
Mass text replacement in WordPress posts (articles):
UPDATE wp_posts SET post_content = REPLACE (post_content, 'old_text', 'new_text');
Replacing image paths:
UPDATE wp_posts SET post_content = REPLACE (post_content, 'https://www.my_site.ru/images/old/', 'https://www.my_site.ru/images/new/');
Replacing links in comments:
UPDATE wp_comments SET comment_content = REPLACE (comment_content, 'http://test.mediasova.com', 'https://mediasova.com');
UPDATE wp_comments SET comment_author_url = REPLACE (comment_author_url, 'http://test.mediasova.com', 'https://mediasova.com');

Mass replacement in MySQL without phpMyAdmin

You can replace any values without logging into phpMyAdmin and creating SQL queries. To do this, you need to:

  1. Create a database dump and download it
  2. Open it in a text editor (e.g., Notepad++)
  3. Search and replace the required values (replace using the mask: Ctrl + H)
  4. Save the changes and replace the old database on the server with the modified one

SEO Specialist Tip: When changing the website’s address, it’s essential to immediately replace all old URLs in the database with new ones (if absolute links were used). You should replace not only the main URL and menu links but also the paths to images, links within texts, or comments (if internal linking was used).