wordpress - mysql - update path in all posts

Posted on 2016-08-16
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 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 100 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 , '', '')
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

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"]
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

LVL 58

Assisted Solution

by:Julian Hansen
Julian Hansen earned 200 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 58

Accepted Solution

Julian Hansen earned 200 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 58

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 58

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 100 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 100 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 "" and then select ALL tables check box . Run it.

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
The purpose of this video is to demonstrate how to reset a WordPress password if you are locked out and cannot reset the password. A typical use would be if you cannot access the email to which WordPress would send the password recovery email to…
The purpose of this video is to demonstrate how to Test the speed of a WordPress Website. Site Speed is an important metric of a site’s health. Slow site speed can result in viewers leaving your site quickly and not seeing your content. This…

631 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