Fall Sale! Code FALL2024 takes 25% OFF our Pro Plugins & Books »
Web Dev + WordPress + Security

WordPress Tip: Update Email Address in the WordPress Database

Several months ago, I changed my email address to stop spam. Since then, I have been updating every instance of my old address that I can find. In WordPress, I edited all of my theme files and updated my profile information in the “Users” admin area. Several days later while digging through the comments table in the WordPress database, I realized that the user-profile update is only pro-actively effective. There were still hundreds of instances of my old email address associated with comment-author information in the comments table. No big whoop for some, but the devastating inconsistency of it all would have kept me from a good night’s sleep (or maybe that was the caffeine..).

Oooh, shut up and fix it, then

To find my way out of this living nightmare, I began with a little research: a couple of quick queries to determine the total number of

  • old email addresses
  • new email addresses

Made a note of that info, and then executed this magical SQL biscuit:

UPDATE `wp_comments` SET `comment_author_email` = REPLACE( comment_author_email, 'old-email@address.com', 'new-email@address.com' );

Fun stuff. This query essentially replaces all instances of “old-email@address.com” with “new-email@address.com” within the “comment_author_email” field of the “wp_comments” table of the WordPress database. Thus, to drop this steaming little turd for yourself, replace both old and new email addresses with the real dealz. Also, if you are using a custom (i.e., non-default) WordPress table prefix (i.e., something other than “wp_”), you will need to edit “wp_comments” accordingly. As always, it is probably a good idea to backup your database before attempting any modification.

After running this query, all instances of your email address should reflect your new information. To double-check that everything went according to plan, rerun the queries for both old and new email info. If all went according to plan, your old email address should return zero results, and your new email address should return x number of results, where “x” is the sum of old and new email addresses determined above.

Want more awesome SQL recipes? Check out Wizard’s SQL Recipes for WordPress 🪄 Features over 300 recipes and an entire chapter on optimizing the WP database! Check out the PDF Demo and get the book »

Hopefully this exercise will help others clean up old email information. The query can also be used for other “find and replace” operations. By using different query values, you can use this code to find and replace just about anything, anywhere! Amazing.. 

About the Author
Jeff Starr = Creative thinker. Passionate about free and open Web.
Banhammer: Protect your WordPress site against threats.

2 responses to “WordPress Tip: Update Email Address in the WordPress Database”

  1. Thanks so much for this. I knew there had to be a way to match all my comments to my updated email address — it’s always fun to play around with phpMyAdmin! Take that, WordPress!

  2. Jeff Starr 2009/07/19 9:22 pm

    My pleasure, sam — thanks for the feedback :)

Comments are closed for this post. Something to add? Let me know.
Welcome
Perishable Press is operated by Jeff Starr, a professional web developer and book author with two decades of experience. Here you will find posts about web development, WordPress, security, and more »
BBQ Pro: The fastest firewall to protect your WordPress.
Thoughts
I disabled AI in Google search results. It was making me lazy.
Went out walking today and soaked up some sunshine. It felt good.
I have an original box/packaging for 2010 iMac if anyone wants it free let me know.
Always ask AI to cite its sources. Also: “The Web” is not a valid answer.
All free plugins updated and ready for WP 6.6 dropping next week. Pro plugin updates in the works also complete :)
99% of video thumbnail/previews are pure cringe. Goofy faces = Clickbait.
RIP ICQ
Newsletter
Get news, updates, deals & tips via email.
Email kept private. Easy unsubscribe anytime.