Currently seeking new career opportunities in web development, particularly with Laravel, Hire Me

MySQL find and replace

David Carr

Tutorials PHP & MySQL

There are times when you need to bulk update a database. Such as changing all references of domain.com to domain.blog in a table of hundreds of records. Doing this manually would be very tedious a better way is to do a find and replace in MySQL directly.

How this works is you do an update specify the table then set the column to be updated and inside a replace command set the column then what you’re looking for and what to replace it with.

update table set column = replace(column,'find','replace')

A practical example of this is:

update posts set content = replace(content,'daveismyname.com','dcblog.dev')

 

Laravel Modules Your Logo Your Logo Your Logo

Become a sponsor

Help support the blog so that I can continue creating new content!

Sponsor

My Latest Book

Modular Laravel Book - Laravel: The Modular way

Learn how to build modular applications with Laravel Find out more

Subscribe to my newsletter

Subscribe and get my books and product announcements.

Learn Laravel with Laracasts

Faster Laravel Hosting

© 2006 - 2024 DC Blog. All code MIT license. All rights reserved.