Search and replace in SQL

The place to talk about things that are related to CMS Made simple, but don't fit anywhere else.
Post Reply
davids355
Power Poster
Power Poster
Posts: 279
Joined: Fri Apr 04, 2008 10:08 am
Location: UK

Search and replace in SQL

Post by davids355 »

I think I done something pretty stupid a long time ago with my CMS install - I decided I would speed things up by moving all (most) of the media (images, JS, Flash etc) to another server, and reference it from there, sort of like a CDN.

Anyway, now I have decided to revert those changes, and I have modified the main templates, stylesheets etc, but I have made a lot of references to this URL throughout the content of the site.

Now I am wondering, is it possible for me to export the database, search and replace this URL (I have now put the files in the root of the install, so I can just remove the root URL of the other server and it will leave a local path to the files - /files/images/etc) and then re import?
User avatar
frankmanl
Power Poster
Power Poster
Posts: 425
Joined: Sat Jul 12, 2008 3:50 am

Re: Search and replace in SQL

Post by frankmanl »

Yes, can be done, even without exporting your database, as long as you can use phpMyAdmin or something like it to approach your database.
In phpMyAdmin you can enter SQL commands to replace strings.

Code: Select all

update TABLE_NAME set FIELD_NAME = replace(FIELD_NAME, ‘find this string’, ‘replace found string with this string’);
But PLEASE: be sure to make a back up before you do this, to prevent further harm.

I've been changing a lot of table content for some project, using SQL commands. Google really was my friend.
davids355
Power Poster
Power Poster
Posts: 279
Joined: Fri Apr 04, 2008 10:08 am
Location: UK

Re: Search and replace in SQL

Post by davids355 »

frankmanl wrote:Yes, can be done, even without exporting your database, as long as you can use phpMyAdmin or something like it to approach your database.
In phpMyAdmin you can enter SQL commands to replace strings.

Code: Select all

update TABLE_NAME set FIELD_NAME = replace(FIELD_NAME, ‘find this string’, ‘replace found string with this string’);
But PLEASE: be sure to make a back up before you do this, to prevent further harm.

I've been changing a lot of table content for some project, using SQL commands. Google really was my friend.
Thanks. Ill look up the rest, I just wasnt sure because I have heard that to do it on some systems you have to use a special program, something to do with the way some systems record field length so that if its changed manually, it messes things up.

thanks for the help. will report back here with details once I have done it.
Post Reply

Return to “The Lounge”