I recently developed a Drupal powered site for a client on a test sub-domain. We then went live and everything was fine since Drupal doesn’t use the domain name in any links. The only problem was that the TinyMCE WYSIWYG editor we had used had put the sub-domain in the URL of some images they had included in various pages. Since I wanted to remove the test sub-domain as it was no longer needed and since it would prevent Google finding duplicate content, I wanted to remove any mention of it from the database.
Turns out that it you know the name of the fields and tables that could contain a mention of text you need to remove or replace, you can issue the below SQL to find and replace it.
UPDATE table SET field = REPLACE(field, "oldtext", "newtext");
If you aren’t sure which table or field could contain your text, since this is an SQL statement, you could use PHP and DESCRIBE TABLE or similar to run the command across every table and field in your database.