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.
About this guide
This guide shows how to replace text inside a MySQL column safely when you need to fix URLs, rename domains, correct repeated words, update file paths, or clean up old text patterns in bulk. It focuses on practical update work, previewing affected rows first, and avoiding mass changes that touch the wrong data.
How to follow this guide
- Preview the rows that contain the old text before updating anything.
- Use REPLACE() inside an UPDATE statement to change the text.
- Limit the update with a WHERE clause so only intended rows are changed.
- Back up the table first if the column contains important data.
- Verify the result after the update before moving on to other changes.
Why use this method?
Bulk text replacement is one of the fastest ways to clean or migrate data, but it is also easy to run too broadly and change more rows than intended. A safe replace workflow prevents unnecessary cleanup and rollback work.
Frequently Asked Questions
What does REPLACE() do in MySQL?
It returns a string where every occurrence of the target text is replaced with the new text.
Can I replace text in only some rows?
Yes. Use a WHERE clause so the UPDATE only touches the rows you want.
Will REPLACE() update all matching occurrences inside the same value?
Yes. Every matching occurrence in that string value is replaced.
Should I preview the affected rows before updating?
Yes. Preview first so you know exactly what will change before running a bulk update.