wordpress - mysql - update path in all posts

Posted on 2016-08-16
Medium Priority
Last Modified: 2016-09-26

We have moved a wordpress site from a temporary server to the new server.

The mysql database is littered with the path details for anything from images to posts with the following in long lines in the database etc etc

Is there a command i can use to search for any reference for the above to change it to

http://mydomain.com/etc etc etc

Or is there another way to do this?

I have tried changing the permalink to default the back again but no joy there
Question by:David
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 143

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 400 total points (awarded by participants)
ID: 41757795
I know how to technically do this in mysql, given the table and column name:

update yourtable set yourcolumn = replace(yourcolumn , '', 'http://mydomain.com/')
where yourcolumn  like '%'

Open in new window

what I don't know is the relevant table/column name(s) in wordpress

Author Comment

ID: 41757812
performing a search in all tables in the database in phpMyAdmin i get many results in many tables, please see attached image

So i want any reference to to be changed to just http://mydomain.com

Author Comment

ID: 41757818
for example one post in the MySQL is

css=".vc_custom_1470043286616{padding-bottom: 40px !important;background: #e7ebf0 url( wp-content/uploads/2016/05/rion-Key-Drivers.jpg?id=970) !important;background-position: center !important;background-repeat: no-repeat !important;background-size: cover !important;}" el_class="related"][vc_column][vc_column_text disable_pattern="false" align="center"]
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

LVL 59

Assisted Solution

by:Julian Hansen
Julian Hansen earned 800 total points (awarded by participants)
ID: 41757819
There are plugins you can use for migrating it one such tool is this one


If you cannot use that then you have an interesting time ahead of you.

You can export your database to an SQL file and then do a search and replace and then import the modified script - however this is not always a failsafe way of doing this because sometimes URL's are stored inside serialized arrays which means that when you change the URL - if the length changes you also have to change the length specifier for the url field. If you are not familiar with PHP serialize then this might become quite technical - it also means it can take a long time.

You can recognise a serialised array when it looks something like this


Open in new window

Try the migration plugin first.

Author Comment

ID: 41758105
unfortunately the plugin copied over the path

I think we can do this by some kind of query on each table but advice on this would be appreciated

Author Comment

ID: 41758126
for example in the wp0m_posts table there are 2368 items int eh post_content"  that need to be found and replaced
LVL 59

Accepted Solution

Julian Hansen earned 800 total points (awarded by participants)
ID: 41758131
If you are going to do the DB method then I recommend the second method I described in my earlier post.

1. Dump your DB to an SQL file
2. Open the file in a text editor
3. Do a search and replace operation using the old URL as the search and the new URL as the replace.
4. Save the file back to the SQL file
5. Restore the target DB from the modified SQL file

This will have the same effect as running a query on tables but will be (in my view) quicker and easier.

Just bear in mind the note I made about plugins that save paths in serialized strings - you might not have any of these but just in case you do.
LVL 59

Expert Comment

by:Julian Hansen
ID: 41758134
addendum - the advantage of the above method is you don't need to know the structure / use of the tables. This reduces to a search and replace operation. Once the DB is restored paths throughout the DB should be changed.

Author Comment

ID: 41758185
That was a great tip and updated all the links!!

The problem i have now is the site has a few issues now with image sizes and the logo has reverted back to the template default. Do you know why this migth be?
LVL 59

Expert Comment

by:Julian Hansen
ID: 41758222
If you search the old db for the logo image and then find the corresponding in the new - what is the difference?

If you just replaced the domain names and paths for the URL's it should not affect the image sizes.

Assisted Solution

Donna earned 400 total points (awarded by participants)
ID: 41758621
Use the Velvet Blues plugin ...and search and read before you decide about the GUID paths...if your site was already active, you may want to leave those alone. That's the best way.. and you can deactivate or uninstall once you are done with it.

If you are moving a site, I like the WP-Migrate plugin. (in fact, I like it for plain old DB backups too!)
LVL 13

Assisted Solution

by:Abhijeet Rananaware
Abhijeet Rananaware earned 400 total points (awarded by participants)
ID: 41758665
Use search and Replace plugin for Wordpress. Its Good and works like a charm.

Their is option to do Dry Run first.

In Search for field put ""
and replace with field put "http://mydomain.com" and then select ALL tables check box . Run it.

Featured Post

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
The purpose of this video is to demonstrate how to integrate Mailchimp with WordPress, by placing a Mailchimp signup form on a WordPress Page or Post. This will be demonstrated using a Windows 8 PC. Mailchimp will be used. Log into your Mailchi…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question