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.
- Connect to your server or shared 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.sqlEnter 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.
More info
- Return to Database find and replace.
- If you are unfamiliar with using SSH, you may wish to try using a Search & Replace plugin or text editor.