ScanSkill
Sign up for daily dose of tech articles at your inbox.
Loading

How To Update WordPress Permalink By SQL Query

How To Update WordPress Permalink By SQL Query
How To Update WordPress Permalink By SQL Query

Sometimes you might want to change the domain name of your great website powered by WordPress. In many cases, you can change the permalink of WordPress from the admin dashboard provided by WordPress itself. But in some situation where it might not be possible to access the dashboard and you only have access to the database of the WordPress site.

So, to help you with such situation here is the query snippet that might be helpful to update WordPress permalink by SQL query.

Note: Please change db_prefix with the value either by looking to your WordPress site database or wp-config.php file. 

UPDATE dbPrefix_options SET option_value = replace(option_value, 'www.oldpermalink.here' , 'www.newpermalink.here') WHERE option_name = 'home' OR option_name = 'siteurl'; 

UPDATE dbPrefix_posts SET guid = replace(guid, 'www.oldpermalink.here' , 'www.newpermalink.here'); 

UPDATE dbPrefix_posts SET post_content = replace(post_content, 'www.oldpermalink.here' , 'www.newpermalink.here'); 

UPDATE dbPrefix_postmeta SET meta_value = replace(meta_value,'www.oldpermalink.here' , 'www.newpermalink.here');

If you have an only .sql file of the WordPress site, then you might want to search and replace old URL with the new one and importing .sql file to the database, then you are good to go.

Steps to update WordPress permalink by SQL query.

update WordPress permalink by SQL query
update WordPress permalink by SQL query
  1. Login to your MySQL using any client available may be phpmyadmin, sequel pro or any other you might be using.
  2. select your WordPress site database and copy paste the above query snippets.
  3. Make the necessary changes on the query snippets and run the query and you are done.
Sign up for daily dose of tech articles at your inbox.
Loading