I have taken over a Drupal 7 site which used to be on a different server and has now moved to ours. I have discovered that on lots of Pages, there are images which point to the wrong server name, the name being hard coded on the page. To save me having to load up each page to test (there are 1000's of them), I thought I could search the database for the value I wish to change. I can see page information is stored in the node table but thats just the page title, created at, type etc. Which table is the text on the page stored in? I have checked the settings.php file and the correct server name is in there. If I edit a page, I can see the html for the images that don't show on the page point to a completely different server
1 Answer
Here's a SQL-centric explainer: each field in Drupal 7 has two storage tables associated with it:
- field_data_{name-of-field}
- field_revision_{name-of-field}
In both cases, the field contents will be in a column like {name-of-field}_value
. You can run a MYSQL UPDATE with a REPLACE function to bulk update URLs in these tables.
So if you find that the text you need to update is in the 'field_body' table:
UPDATE field_data_field_body SET field_body_value = REPLACE(field_body_value, 'oldurl.com', 'newurl.com');
UPDATE field_revision_field_body SET field_body_value = REPLACE(field_body_value, 'oldurl.com', 'newurl.com');
Immediately after running these queries, you must clear the Drupal cache. This is best done from the "Performance" admin page in the Drupal UI. If you insist on SQL-only remedies, you can clear the particular relevant cache with this:
TRUNCATE TABLE cache_field;
The regular caveats apply:
- Have a backup of your database ready, and verify that the backup you have restores correctly!
- Be judicious about your REPLACE functions, that you don't accidentally replace more than what you thought you were targeting.
- Yes, you should perform the REPLACE against both the data and the revision tables.
field_data_body
. You can export the db and do a text replacement if you know what you're doing, then import it back. Other options are Feeds module, export into CSV, reimport after fixing it, or create a Text format filter that you can enable on text formats used on the Body that replace the string you want.