tsoHost Help Centre

Table of Contents

Find and replace for WordPress with SSH

Updated May 4th, 2021 at 15:48 BST

For experienced users, it can be more efficient to use SSH when managing WordPress, and performing tasks such as a search and replace in the database.

Warning: Make a backup of your database before making any changes.

Connect to your Managed WordPress hosting account with SSH.

Export your WordPress database.

Open the dump file with the vim text editor with the following command:

        vim filename.sql

Update the command with the following information:

      filename.sql is the name of the dump file you just created

Note: If your current working directory is different than your working directory at the time the dump file was created, then you will need to include the path to the file in the command. For example:

        vim /home/user/public_html/filename.sql

Enter command mode by typing the colon (:) character.

Once in command mode, execute a search and replace with the following command:

    %s/OldDomain/NewDomain/g

Update the command with the following information:

            OldDomain is your old domain or data
            NewDomain if your new domain or data

Press Enter to run the command, which will execute a search and replace of the old domain/data with the new domain/data.

Press Esc to exit the insert/append mode.

Type the following command to enter command mode, save the file and exit:

             :wq

Import your updated database using SSH.

Next steps: If you using this process to change your domain name, then you may also need to update the change the domain on your hosting account.