• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 48
  • Last Modified:

wordpress - mysql - update path in all posts

Hi,

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

http://185.123.97.162/~username/mydomain.com/etc 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
Thanks
0
David
Asked:
David
5 Solutions
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
I know how to technically do this in mysql, given the table and column name:

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

Open in new window


what I don't know is the relevant table/column name(s) in wordpress
0
 
DavidAuthor Commented:
performing a search in all tables in the database in phpMyAdmin i get many results in many tables, please see attached image

phpMyAdmin
So i want any reference to http://185.123.97.162/~username/mydomain.com/ to be changed to just http://mydomain.com
0
 
DavidAuthor Commented:
for example one post in the MySQL is

css=".vc_custom_1470043286616{padding-bottom: 40px !important;background: #e7ebf0 url(http://185.123.97.162/~username/mydomain.com/ 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"]
0
Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

 
Julian HansenCommented:
There are plugins you can use for migrating it one such tool is this one

https://wordpress.org/support/plugin/all-in-one-wp-migration

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

a:11:{i:1;O:8:"stdClass":5:{s:17:"http://mysite.com"}}

Open in new window


Try the migration plugin first.
0
 
DavidAuthor Commented:
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
0
 
DavidAuthor Commented:
for example in the wp0m_posts table there are 2368 items int eh post_content"  that need to be found and replaced
0
 
Julian HansenCommented:
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.
0
 
Julian HansenCommented:
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.
0
 
DavidAuthor Commented:
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?
0
 
Julian HansenCommented:
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.
0
 
DonnaCommented:
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!)
0
 
Abhijeet RananawareWeb & Mobile DeveloperCommented:
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 "http://185.123.97.162/~username/mydomain.com"
and replace with field put "http://mydomain.com" and then select ALL tables check box . Run it.
0

Featured Post

Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now