Hello Friends,
I've around 1000 records in mysql database. in content table im using image source url like 'img.mydomain.com' so today I've registered new domain. so i want to find replace following domain and update my new domain in image path url. so please let me know how to find/replace???

thanks waiting for reply..

Dani AI

Generated

pointed toward doing it in SQL and offered to script it β€” below is a concise, safer workflow you can follow that avoids breaking data and lets you preview changes before committing them.

Always back up the table first:

mysqldump -u username -p database_name content_table > content_table_backup.sql

Preview how many rows and see context before changing anything:

SELECT COUNT(*) AS matches
FROM content_table
WHERE content LIKE '%img.mydomain.com%';

SELECT id,
       SUBSTRING(content, GREATEST(LOCATE('img.mydomain.com', content)-30,1), 120) AS snippet
FROM content_table
WHERE content LIKE '%img.mydomain.com%'
LIMIT 20;

Perform the replacement using MySQL's REPLACE() so only the URL text is changed (adjust protocol and trailing slash to match your stored values). Wrap updates in a transaction if you use InnoDB:

START TRANSACTION;

UPDATE content_table
SET content = REPLACE(content, 'http://img.mydomain.com/', 'http://img.newdomain.com/')
WHERE content LIKE '%img.mydomain.com/%';

-- verify a few rows now, then:
COMMIT;

Cautions:

  • If the stored HTML sometimes omits the protocol (starts with "img.mydomain.com") do a separate REPLACE for that case.
  • If your table uses MyISAM there is no transactional rollback β€” rely on the backup.
  • Do not run blind replacements on serialized PHP data: changing string lengths will corrupt the serialization. For serialized data, use a script that unserializes, updates values, and then reserializes (or use a battle-tested tool for CMS databases).

MySQL REPLACE reference: REPLACE() function. Mysqldump reference: mysqldump.

Recommended Answers

All 2 Replies

You can update all directly from MySQL

mysql -> UPDATE yourTable SET ON yourField='newLink' WHERE yourField='oldLink'

szabizs Just gave you the sutff.

However if you really want to search and replace. Please advice and i will script something for you.
;)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.