Solved

wordpress - mysql - update path in all posts

Posted on 2016-08-16
13
31 Views
Last Modified: 2016-09-26
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
Comment
Question by:David
13 Comments
 
LVL 142

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 , '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
 

Author Comment

by:David
ID: 41757812
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
 

Author Comment

by:David
ID: 41757818
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
 
LVL 52

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

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
 

Author Comment

by:David
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
0
 

Author Comment

by:David
ID: 41758126
for example in the wp0m_posts table there are 2368 items int eh post_content"  that need to be found and replaced
0
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 
LVL 52

Accepted Solution

by:
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.
0
 
LVL 52

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.
0
 

Author Comment

by:David
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?
0
 
LVL 52

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.
0
 
LVL 3

Assisted Solution

by:Donna
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!)
0
 
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 "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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

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 article discusses how to create an extensible mechanism for linked drop downs.
The purpose of this video is to demonstrate how to manually back up a WordPress Database. This will be demonstrated using a Windows 8 PC. The Host used will be IPage.com Log into your Hosting account. IPage will be used for demonstration : Locat…
The purpose of this video is to demonstrate how to exclude a particular blog category from the main blog page. This is can be used when a category already has its own tab, or you simply want certain types of posts not to show up on the main blog. …

910 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now