[Snippet] How to Search and Replace String in MySQL or PHPMyAdmin

Posted on

Imagine, you have a 10K records in a table in your database. And on each line, there is a character that you want to remove or replaced with other characters. If do it manually, it may take days. Creating a system or script to solve the problem it was still takes a lot of times.

I have even had a case like this and I am looking on the internet. Turns out there and very simple. MySQL has a replace function similar to PHP. Just use this in phpmyadmin  and all your problems will be completed.

UPDATE `table`
SET `field` = replace(field, 'unwanted_char', 'wanted_char')

Problems are solved in seconds… very help me.

Gravatar Image
Web developer, big fan of CakePHP, loving wordpress soo much. You can found him on Google+ and Facebook. Dont forget to follow him on Twitter.