How to Replace Text in MySQL Column
Update repeated text patterns safely in a MySQL column without changing more rows than intended.
Before you start
Preview the rows that will be affected
Before using UPDATE, find the rows that currently contain the old text pattern.
SELECT id, content
FROM articles
WHERE content LIKE '%old-domain.com%';
This lets you confirm that the target text appears exactly where you expect before any data is changed.
Replace text in one column
Use REPLACE() inside an UPDATE statement to swap the old text with the new one.
UPDATE articles
SET content = REPLACE(content, 'old-domain.com', 'new-domain.com')
WHERE content LIKE '%old-domain.com%';
It updates only rows that contain the old text and replaces every matching occurrence inside that column value.
Replace text in a URL column
A common real-world case is moving from one domain to another or fixing an old URL pattern stored in a column.
UPDATE links
SET url = REPLACE(url, 'http://oldsite.com', 'https://newsite.com')
WHERE url LIKE '%oldsite.com%';
Useful after domain changes, SSL migration, or fixing old internal links stored in the database.
Replace text in only a subset of rows
Sometimes the old text appears in many places, but you only want to change one group of rows.
UPDATE products
SET description = REPLACE(description, 'Old Brand', 'New Brand')
WHERE category_id = 5
AND description LIKE '%Old Brand%';
The WHERE clause prevents a broad replacement across the entire table when only one subset should change.
Back up the table before a big replacement
If the update will affect many rows or important content, make a backup copy first.
CREATE TABLE articles_backup_20260402 AS
SELECT *
FROM articles;
If the replacement result turns out wrong, a backup table gives you a quick recovery path.
Verify the result after the update
After running the replacement, check a few rows and confirm the old text is gone where it should be.
SELECT id, content
FROM articles
WHERE content LIKE '%new-domain.com%'
LIMIT 20;
Also run a quick search for the old text to make sure only the intended rows were changed and no old values remain unexpectedly.
Common real-world situations
Replace old URLs stored in articles, settings, or link tables after moving to a new domain.
Update repeated brand names or product labels across stored descriptions and notes.
Fix old path fragments in stored file references after folder changes or server migration.
Correct repeated spelling or wording patterns across a large number of stored records.
Common mistakes
Always inspect the matching rows before bulk replacement so you know what will change.
A missing WHERE clause can update far more rows than intended, even if the replacement text is common.
If the target string is short or generic, it may modify valid content in ways you did not expect.
For large or critical updates, a quick backup table is the safer move before bulk replacement.