Find and replace for WordPress with SSH


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.

  1. Connect to your server or shared hosting account with SSH.
  2. Export your WordPress database.
  3. Open the dump file with the vim text editor with the following command:

    vim filename.sql

    Update the command with the following information:

    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
  4. Enter command mode by typing the colon (:) character.

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

    %s/OldDomain/NewDomain/g

    Update the command with the following information:

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

  7. Press Esc to exit the insert/append mode.
  8. Type the following command to enter command mode, save the file and exit

    :wq
  9. Import your updated database using SSH.


Article ID: 1237
Created On: Tue, Nov 17, 2020 at 7:01 PM
Last Updated On: Wed, Nov 18, 2020 at 9:56 PM

Online URL: https://www.heartinternet.uk/support/article/find-and-replace-for-wordpress-with-ssh.html