Update a MySQL table from the command line (find and replace)

I thought this might be helpful to some of you out there, as I routinely have to do this myself. Need to update a table, or a lot of rows of data in MySQL? Here is a handy Find and Replace SQL script to run at the command line.

mysql> update TABLENAME set FIELDNAME  = replace(FIELDNAME, 'X','Y');

In the above example, X is the existing text and Y is the new text you want to replace with. Have fun!

Chris

Chris started building web sites and web applications in 1996, after installing Linux and discovering httpd. It was a career in freshwater fisheries and geographic information systems (GIS) that led Chris to the web, and to start Lanexa.net in 1998. Chris has a strong background in Linux/Unix systems administration, HTML, CSS, PHP, as well as Oracle and MySQL database administration. Chris is a proven leader, having lead the development of ecommerce platforms for Fortune 500 companies, as well as start ups. He is able to bridge the gap between Marketing and IT, and turn business requirements into development objectives, and he delivers results. When Chris is not working on web sites, he is usually chasing his kids around or playing mandolin. Finalist, San Diego Magazine's Top Tech Exec Awards, 2012, 2013 Council Member, Magento X-Commerce Merchant Council, 2011

Leave a Reply

Your email address will not be published. Required fields are marked *