Change WordPress URL in Database (SQL)

Did you copy your WordPress to a new URL or domain name, and having trouble accessing it now?

Are you getting redirected to the old URL, and can’t access settings in WordPress admin?

👉 Let’s fix that!

Log into your MySQL or MariaDB and run this

Log into your database in order to run SQL commands against it. You can use e.g. a web interface or the command line.

If you’re using docker, you might log into your database with a command like this:

Bash
docker exec -it <your_container_name> mysql -p -u <db_user> <db_name>

This will prompt for your database password. If you’re not using a password, remove the -p parameter.

Update siteurl and home wp_options

Once you’re in your database, let’s get down to business:

SQL
UPDATE wp_options SET option_value = 'http://localhost' WHERE option_name = 'siteurl';

UPDATE wp_options SET option_value = 'http://localhost' WHERE option_name = 'home';

These two SQL commands will update the URLs WordPress thinks it is located at, and it will no longer automatically redirect to your old URL.

Great!

Replace localhost with the domain you will be accessing WordPress from. For example https://my-new-wordpress.net.

Troubleshooting notes

If it seems like WordPress is STILL redirecting you to the old URL, it’s probably because of your browser.

Browsers can be persistent on caching the redirect, so you might need to clear the browser cache, try incognito mode, or try accessing a different path, e.g. a post URL or the /wp-admin URL, to go around the redirect.

Thanks for reading. Enjoy your wordpressing!

Katso myös