Our blog
MySQL Find and Replace
One of the most common things that needs to be done when tidying up a database is to bulk find and replace data in MySQL tables. This can be for things like spelling mistakes, changing categories of products or any other value held in a MySQL database table.
Its an easy thing to do though and here is the code:
-
UPDATE [table_name] SET [field_name] = REPLACE([field_name],'[string_to_find]','[string_to_replace]');
note - nice syntax highlighting plugin used is mentioned here
More Reading:
One Comments
|
I must admit finding the MySQL REPLACE function has saved me so much time. I particularly use it when moving a development site from one server to another. In fact I used it so much I thought it would be nice to write a PHP script that would find and replace across a whole MySQL database - I posted it here if you are interested: http://www.mjdigital.co.uk/blog/search-and-replace-text-in-whole-mysql-database/ It has now gone under GPL on LaunchPad and I'd love any good developers to make it better. |
RSS Feed
MJ7
December 9th, 2009